I am having an intriguing problem where whenever I use add_header
in my virtual host configuration on an ubuntu server running nginx with PHP and php-fpm it sim
I don't think it works properly by reloading ==> nginx -s reload
When I used add_header and then reloaded, nothing changed in response. But when I made a deliberate error and saw a 404 error on the client side, and then fixed my deliberate error and reloaded again, Add_header worked.
Firstly, let me say that after looking around the web, I found this answer popping up everywhere:
location ~* \.(eot|ttf|woff|woff2)$ {
add_header Access-Control-Allow-Origin *;
}
However, I have decided to answer this question with a separate answer as I only managed to get this particular solution working after putting in about ten more hours looking for a solution.
It seems that Nginx doesn't define any [correct] font MIME types by default. By following this tuorial I found I could add the following:
application/x-font-ttf ttc ttf;
application/x-font-otf otf;
application/font-woff woff;
application/font-woff2 woff2;
application/vnd.ms-fontobject eot;
To my etc/nginx/mime.types
file. As stated, the above solution then worked. Obviously, this answer is aimed at sharing fonts but it's worth noting that the MIME types may not be defined in Nginx.