为什么我的Nginx Web服务器不处理ttf字体? [英] Why isn't my nginx web server handling ttf fonts?

查看:666
本文介绍了为什么我的Nginx Web服务器不处理ttf字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究由于CORS限制而无法在远程站点上呈现特定字体文件的问题.

I've been researching this issue where a specific font file isn't rendered on remote sites because of CORS restrictions.

到目前为止,我已经能够识别出对该URL的请求正在使用access-control-allow-origin进行响应,但是nginx在远程进行时拒绝了对该字体的请求.

So far I have been able to identify that requests for that url are responding with access-control-allow-origin, but nginx is rejecting requests for that font when made remotely.

我使用的是laravel和spatie的laravel-cors插件,但我不认为这样会返回不是从laravel路线呈现的样式表或字体的标头信息.

I am using laravel and the laravel-cors plugin from spatie, but I wouldn't think that would return header information for a style sheet or font not rendered from laravel routes.

有人知道为什么会这样吗?

Does anyone know why this would happen?

我的错误

Access to font at 'https://example.com/css/widget-icons/icomoon.ttf?wiodlm' from origin 'http://www.second-example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

通过curl检索的标头(似乎允许curl请求)

curl -I https://example.com/css/widget-icons/icomoon.ttf?wiodlm

HTTP/2 200 
date: Sun, 13 Jan 2019 16:57:34 GMT
content-type: application/x-font-ttf
content-length: 1316
set-cookie: AWSALB=r3yRudj6XwTlfaFzEdtxrecHzLLplOKlpRMbKuqL8InwUQYylNVFaZtmGHK2wQDgjvaXsBtRVcTCyjWidjTFUFmoDzKLBLH0gL6qarns38Qn4FuDNCZogawHtOjD; Expires=Sun, 20 Jan 2019 16:57:34 GMT; Path=/
server: nginx/1.14.1
last-modified: Tue, 25 Dec 2018 05:42:49 GMT
etag: "5c21c359-524"
expires: Thu, 31 Dec 2037 23:55:55 GMT
cache-control: max-age=315360000
access-control-allow-origin: *
accept-ranges: bytes

我的nginx配置为Access-Control-Allow-Origin(已设置为适当的区分大小写).

location ~* .(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|wml|swf|ttf|ttc|otf|eot|woff|woff2)$ {
        add_header Access-Control-Allow-Origin "*";
        expires max;
}

添加了模仿类型以通过ttf

application/x-font-ttf           ttc ttf;
application/x-font-otf           otf;
application/font-woff                            woff;
application/font-woff2           woff2;

推荐答案

我通过将用于ttf的mime.types从application/x-font-ttf修改为font/ttf,解决了此问题.

I resolved this issue by modifying the mime.types used for ttf from application/x-font-ttf to font/ttf.

我的Nginx配置

    location ~* .(js|css|ttf|ttc|otf|eot|woff|woff2)$ {
            add_header access-control-allow-origin "*";
            expires max;
    }

mime.types文件

mime.types edit. 
    application/x-font-ttf           ttc;
    application/x-font-otf           otf;
    application/font-woff2           woff2;
    font/ttf                         ttf;

这篇关于为什么我的Nginx Web服务器不处理ttf字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆