web应用通常会碰到跨域的问题,特别是在将字体文件放在另一个域名下(cdn缓存)的时候会出现无法访问的问题,浏览器会报如下错误警告:
Font from origin ‘http://cdn.xxxx.com‘ 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://www.xxxx.com‘ is therefore not allowed access.
意思是说 http://www.xxxx.com 不被 http://cdn.xxxx.com 服务跨域允许,需要在 nginx 的 cdn.xxxx.com服务的配置中加上跨域允许的配置:
add_header Access-Control-Allow-Origin http://www.xxxx.com; add_header Access-Control-Allow-Headers Origin,X-Requested-With,Content-Type,Accept; add_header Access-Control-Allow-Methods POST,GET; add_header Access-Control-Allow-Credentials true;
重启nginx就能解决这个问题。
时间: 2024-10-05 14:16:14