Nginx配置跨域请求Access-Control-Allow-Origin

出现跨域错误No 'Access-Control-Allow-Origin' header is present on the requested resource的时候,需要给Nginx配置响应头参数

解决方案

Nginx配置

1
2
3
4
5
location / {  
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
}

参考