【问题标题】:Font-awesome on my own cdn我自己的 cdn 上的字体真棒
【发布时间】:2016-01-27 22:47:14
【问题描述】:

我已经下载了 font-awesome 4.5.0 并安装了我自己的 cdn (cachefly)。然后按照font-awesome 的建议,我使用了指向 css 文件的链接,例如:

<link rel="stylesheet" href="http://mycachefly.cachefly.net/external/font-awesome/4.5.0/css/font-awesome.min.css">

但是,我出现以下错误:

Font from origin 'http://wisa.cachefly.net' 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://localhost' is 
therefore not allowed access.

这里有什么问题?

ps:我没有 .htaccess 文件。它是 extjs 和 angular 的混合项目

【问题讨论】:

标签: angularjs extjs font-awesome cdn access-control


【解决方案1】:

发生这种情况是因为您没有启用 CORS,它允许从您的来源以外的其他域加载资源。某些服务默认启用 CORS,例如 fontawesomecdn

无论您使用的是 Apache 还是 Nginx,此页面底部都有关于在源服务器上启用 CORS 的说明。

Apache - 放在 .htaccess 文件中

<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css|js|gif|png|jpe?g|svg|svgz|ico|webp)$">
    Header set Access-Control-Allow-Origin "*"
</FilesMatch>

Nginx - 放在 nginx.conf 文件中

location ~ \.(ttf|ttc|otf|eot|woff|font.css|css|js|gif|png|jpe?g|svg|svgz|ico|webp)$ {
add_header Access-Control-Allow-Origin "*";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-16
    • 2015-05-06
    • 2020-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多