nginx add_header not working

后端 未结 8 806
无人共我
无人共我 2020-12-23 16:00

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

相关标签:
8条回答
  • 2020-12-23 16:57

    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.

    0 讨论(0)
  • 2020-12-23 16:58

    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.

    0 讨论(0)
提交回复
热议问题