Nginx font rules
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://www.w3.org/TR/cors/#access-control-allow-origin-response-header