Ngingx在本地.ttf字体上返回404

我有一个本地.ttf字体,我需要使用。 我试图编辑MIMEtypes

application/x-font-truetype ttfl 

也试过了

 application/x-font-ttf ttf; 

和mysite.conf看起来像这样:

 server { listen 80; server_name mysite.com www.mysite.com; location / { root /var/www/mysite.com/public_html; index index.html index.htm; try_files $uri $uri/ =404; } location ~* \.(eot|ttf|woff)$ { add_header Access-Control-Allow-Origin *; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } 

但是我仍然得到404的字体。 我究竟做错了什么?

问题在于你在location /块内部指定了root ,而nginx在匹配静态文件的location块中使用了上层的默认root目录。

您需要将root指令移到server级别。