“This is my 9th day of the November Gwen Challenge. Check out the details: [Last Gwen Challenge 2021]

Recently, some users reported that they kept prompting network error when using APP, but the network itself was normal. At first I thought it was carrier hijacking, because it happened a few years ago. The original solution was to configure multiple server domain names into the APP. When you cannot connect to the server but can ping Baidu, then change the ping domain name request.

This time, the user’s access to the server is normal, and the three feedback users are all iphones. Then I did some research. Ios 12 does not support the following cross-domain configurations. Otherwise, a Network error occurs

    add_header 'Access-Control-Allow-Origin' The '*';
    add_header 'Access-Control-Allow-Headers' The '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' The '*';
    if ($request_method = 'OPTIONS') {
       return 200;
    }
Copy the code

It is good to change the following configuration.

location / {

  The following is the new configuration
  # precheck the cache of the command, if not cached will send two requests each time
  add_header Access-Control-Max-Age 3600;
  # Cookie requests require this field and set to true
  add_header Access-Control-Allow-Credentials true;
  # indicates that this domain is allowed to make cross-domain calls (the domain name and port from which the client sends the request)
  # $http_origin does not use * because requests with cookies do not support *
  add_header Access-Control-Allow-Origin $http_origin;
 # Request mode * indicates full support
  add_header 'Access-Control-Allow-Methods' The '*';
  # represents the dynamic retrieval of fields in the request header
  add_header Access-Control-Allow-Headers $http_access_control_request_headers;
  The request will not be sent until the precheck command passes
  Check whether the type of request is a precheck command
  if ($request_method = OPTIONS){
      return 200;
  }
  # Other configurations....

}
Copy the code