Nginx跨域设置

  参考:https://www.cnblogs.com/bninp/p/5694277.html

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

  在Nginx配置的location下添加以下配置

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Credentials: true;
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';
     

  PS:1,Access-Control-Allow-Origin允许跨域的源 * 代表允许所有,可以使用"http://域名"配置

     2,需要在最终的目的Nginx配置,而不能在反向代理的Nginx配置

 

posted @ 2019-03-16 08:48  minseo  阅读(473)  评论(0编辑  收藏  举报