Nginx 配置跨域权限


今天设置静态资源服务器时发现

Font from origin 'http://start.fbzl.org' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://lib.fbzl.org' is therefore not allowed access. 

这里我给静态资源单独设置了一个域名,其它页面调用时发生了跨越权限问题。

Nginx 解决办法:

1 add_header Access-Control-Allow-Origin *;
2 
3 add_header Access-Control-Allow-Headers X-Requested-With;
4 
5 add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

 

将这段代码添加到 http{} 或者静态资源对应的 server{}

如果只为自己的网站使用可以将第一行代码的星号改为自己的域名,例如 *.fbzl.org


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM