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;

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

上一篇 CentOS添加删除用户和用户组
下一篇 Vagrant使用
目录
文章列表
1 Appium自动化测试(4)—— 安装 Appium-Desktop
Appium自动化测试(4)—— 安装 Appium-Desktop
2
TestNG分组测试
TestNG分组测试
3
FastJson校验json字符串是否合法
FastJson校验json字符串是否合法
4
Spring Boot Druid接入总结
Spring Boot Druid接入总结
5
Linux下查看磁盘占用空间
Linux下查看磁盘占用空间
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。