Nginx中Access-Control-Allow-Origin字体跨域请求配置方法

问题:

Access to Font at 'http://www.oahome.cn/packages/admin/google-fonts/fonts/Source-Sans-Pro.woff2' from origin 'http://www.appblog.cn' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.appblog.cn' is therefore not allowed access.

在nginx.conf或vhosts的server下

location ~* \.(eot|otf|ttf|woff|woff2|svg)$ {
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Headers X-Requested-With;
    add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
}

也可以指定允许的url

add_header Access-Control-Allow-Origin http://www.appblog.cn;

注意:需要清空浏览器缓存才能生效

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/02/25/fonts-cross-domain-request-configuration-method-for-access-control-allow-origin-in-nginx/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Nginx中Access-Control-Allow-Origin字体跨域请求配置方法
问题: Access to Font at 'http://www.oahome.cn/packages/admin/google-fonts/fonts/Source-Sans-Pro.woff2' from origin 'http://www.appbl……
<<上一篇
下一篇>>
文章目录
关闭
目 录