Nginx 出现跨域问题
今天nginx出现跨域问题,如下:
Access to XMLHttpRequest at 'https://xxxx/newsalarm/pc/list' from origin 'https://xxxxxx' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
跨域解决方法有两种,第一叫开发修改代码,第二修改nginx配置。nginx修改如下:
add_header Access-Control-Allow-Origin *;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';