Solving nginx cross domain problems

Time:2021-11-27

In the configuration file of nginx, add:

location / {
  add_header Access-Control-Allow-Origin $http_origin;
  add_header Access-Control-Allow-Methods 'GET,POST,OPTIONS';
  add_header Access-Control-Allow-Credentials true;
  add_header Access-Control-Allow-Headers *;
  add_header Access-Control-Max-Age 1728000;
  if ($request_method = 'OPTIONS') {
        return 204;
    }
}