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{}spa

若是隻爲本身的網站使用能夠將第一行代碼的星號改成本身的域名,例如 *.fbzl.orgcode

相關文章
相關標籤/搜索