2

我将 Font-Awesome-Sass-Rails gem 用于图标字体,它们在除 Firefox 之外的所有浏览器中都能正常显示。我目前正在使用 Cloudfront 和 Nginx。这是我的 CORS 配置:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

有任何想法吗?

4

3 回答 3

9

如果上面的答案不能解决任何人的问题,那么这是我的有效解决方案:

# Cross domain webfont access
location ~* \.(?:ttf|ttc|otf|eot|woff|font.css)$ {
add_header "Access-Control-Allow-Origin" "*";
expires 1M;
access_log off;
add_header Cache-Control "public";
}
于 2013-06-24T10:43:15.913 回答
1

当我遇到同样的问题时,我发现唯一对我有用的解决方案是在 nginx 本身中设置一个标头。

location ~* \.(eot|otf|ttf|woff)$ {
    add_header  Access-Control-Allow-Origin *;
}
于 2013-02-26T02:45:27.637 回答
1

上面的例子不起作用,这个起作用了。在 nginx 配置中,将 if 块放在 /assets/ 规则中

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;

    if ($request_filename ~* ^.*?\.(eot)|(ttf)|(woff)|(svg)|(otf)$) {
       add_header Access-Control-Allow-Origin *;
    }
  }
于 2014-01-17T22:13:31.230 回答