Nginx允許跨域訪問的配置問題


網站項目動靜分離,靜態資源服務器A 業務服務器B  B中靜態資源由A加載 出現如下問題:

@font-face {
    font-family: 'iconfont';
    src: url('../fonts/iconfont.eot');
    src: url('../fonts/iconfont.eot?#iefix') format('embedded-opentype'),
    url('../fonts/iconfont.woff') format('woff'),
    url('../fonts/iconfont.ttf') format('truetype'),
    url('../fonts/iconfont.svg#iconfont') format('svg');
}

字體資源無法加載

Access to Font at 'https://kwdst.2ceo.cn/biz//fonts/iconfont.woff' from origin 'http://dev2.lystrong.cn' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://dev2.lystrong.cn' is therefore not allowed access.

為跨域訪問問題,可以在靜態資源服務器A 配置允許跨域請求,nginx在配置中對應的location下添加上如下的設置:

add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';

重啟nginx 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM