尽管这些年来以各种形式提出了这一问题,但没有一个答案对我有效,而有效的解决方案根本就没有意义。
我希望有人能够弄清楚解决问题的原因,或者帮我指出真正的问题。
问题是我们的一些woff2字体无法正确显示,从下面的输出可以看出
Request URL: https://example.com/fontawesome-webfont.af7ae505a9eed503f8b8.woff2?v=4.7.0
Request Method: GET
Status Code: 200
Remote Address: xxx.xxx.xxx.xxx:443
Referrer Policy: no-referrer-when-downgrade
content-encoding: br
content-type: text/html添加一个位置块,如下所示,似乎解决了这个问题,尽管location块本身什么也不做(至少根据我的理解)
location ~* \.(eot|otf|ttf|woff|woff2)$ {
}我还在我的mime.types中映射了以下内容
font/ttf ttf;
font/woff woff;
font/woff2 woff2;
application/font-ttf ttf;
application/font-woff woff;
application/font-woff2 woff2;
application/x-font-ttf ttc ttf;
application/x-font-otf otf;
application/x-font-woff woff;
application/x-font-woff2 woff2;我们用brotli和gzip压缩
发布于 2020-08-22 16:00:35
我也面临着同样的问题。张贴我的解决方案,这样它可能会帮助到某人。对我有用的解决方案
解决方案1
location ~* \.(eot|otf|ttf|woff|woff2)$ {
access_log off;
log_not_found off;
# expires 30d;
add_header Access-Control-Allow-Origin *;
types {font/opentype otf;}
types {application/vnd.ms-fontobject eot;}
types {font/truetype ttf;}
types {application/font-woff woff;}
types {font/x-woff woff2;}
}但是,如果我将上述内容添加到mime.type中,则不起作用。为此,我试着在下面
解决方案2
将此添加到mime.types中
font/opentype otf;
font/truetype ttf;
application/font-woff woff;
font/x-woff woff2;由于定义的顺序,mime.types被默认的应用程序/八位流覆盖。
nginx.conf
添加包含/etc/nginx/mime.type;再次在您的位置块中添加
location ~* \.(eot|otf|ttf|woff|woff2)$ {
access_log off;
log_not_found off;
# expires 30d;
include /etc/nginx/mime.types;
add_header Access-Control-Allow-Origin *;
}备注
如果已启用缓存,请尝试清除一次服务器缓存。另外,如果您正在使用CDN (如cloudflare ),请确保在进行此更改后清除缓存。
https://stackoverflow.com/questions/61884808
复制相似问题