
使用nginx解决Access
前台在访问不同ip的nginx服务器时报:No ‘Access-Control-Allow-Origin’ header is present on the requested resource 原因:被请求的资源没有设置 ‘Access-Control-Allow-Origin’,也就是nginx的返回信头没有Access-Control-Allow-Origin(也就是浏览器同源策略,大家可以自行百度) 解决方案: 在nginx中的nginx.conf中的路由中添加以下代码:
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'; }如果你请求的不是"location /" ,则在自己的路由添加例如:“localhost /test”
👁️ 阅读量:0
© 版权声明:本文《使用nginx解决Access》内容均为本站精心整理或网友自愿分享,如需转载请注明原文出处:https://www.zastudy.cn/wen/1686964362a410333.html。