Nginx和v5问题
虽然这些年来人们以各种形式提出了这个问题,但没有一个答案对我有效,而且有效的解决方案毫无意义。 我希望有人能够理解为什么解决方案能解决问题,或者帮助我指出真正的问题。 问题是我们的一些woff2字体很棒的字体显示不正确,下面的输出可以看出这一点 如下所示添加位置块似乎可以解决问题,尽管至少从我的理解来看,位置块本身没有任何作用 我的mime.types中也映射了以下内容Nginx和v5问题,nginx,nginx-location,font-awesome-5,woff2,Nginx,Nginx Location,Font Awesome 5,Woff2,虽然这些年来人们以各种形式提出了这个问题,但没有一个答案对我有效,而且有效的解决方案毫无意义。 我希望有人能够理解为什么解决方案能解决问题,或者帮助我指出真正的问题。 问题是我们的一些woff2字体很棒的字体显示不正确,下面的输出可以看出这一点 如下所示添加位置块似乎可以解决问题,尽管至少从我的理解来看,位置块本身没有任何作用 我的mime.types中也映射了以下内容 font/ttf ttf; font/woff woff; font/woff2 woff2; app
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进行压缩我也面临同样的问题。发布我的解决方案,以便它可以帮助某人。 对我有效的解决方案 解决方案1 但是,如果我在mime.type中添加上述内容,它将不起作用。所以我在下面试过了 解决方案2 将此添加到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;
由于定义的顺序,mime.types被默认的应用程序/八位字节流覆盖
nginx.conf
添加include/etc/nginx/mime.types;再次在你的位置块内
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,请确保在进行此更改后清除缓存。Bump。。仍然在看一些关于此警告的帮助:请启用expires 30d;当你的问题解决了。
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;}
}
font/opentype otf;
font/truetype ttf;
application/font-woff woff;
font/x-woff woff2;
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 *;
}