Nginx font rules

Linode Staff

Hello,

Some fonts aren't loading from my Linode.

I set up these rules in my nginx configuration:

location ~* .(eot|css|otf|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
}

I keep getting an error stating "No 'Access-Control-Allow-Origin' header is present"

Is there something I should be adding to my configuration to make this work?

Thanks.

2 Replies

I would first check to see if your fonts have default mime types. By default, NGINX has no mime types for fonts. This could be related to the error you received.

To check, navigate to the directory with your configs and locate where the mime types are defined. Typically they are located in the mime.types file. If haven't already done so, you may need to add these strings below to that file:

application/x-font-ttf ttc ttf;
application/x-font-otf otf;
application/font-woff woff;
application/font-woff2 woff2;
application/vnd.ms-fontobject eot;

If the error you are receiving is related to being blocked by CORS policy, try adding this to your vhost configuration:

location ~* .(eot|otf|ttf|woff|woff2)$ {
add_header Access-Control-Allow-Origin *;
}

For more information in reagrds to proper NGINX font configurations, check out these links below:

https://serverfault.com/questions/186965/how-can-i-make-nginx-support-font-face-formats-and-allow-access-control-allow-o

https://www.w3.org/TR/cors/#access-control-allow-origin-response-header

Still, not working.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct