今天开启了阿里云CDN加速之后,静态图片和JS文件可以正常访问,但是请求字体文件时却遇到跨域问题:
报错如下:
Access to font at 'http://static.zjwave.com/templates/jpress_simple/fonts/fontawesome-webfont.woff2?v=4.6.3' from origin 'http://zjwave.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
原因是浏览器跨域访问js、css、img等常规静态资源被同源策略许可,但iconfont字体文件(eot|otf|ttf|woff|svg)例外,此时可在nginx的静态资源服务器中加入以下配置。
location / {
add_header Access-Control-Allow-Origin *;
}
重启Nginx服务之后,问题解决:
相关连接:前端常见跨域解决方案(全)
转载请注明原文链接:ZJ-Wave
匿名用户
好