Set Vary: Accept-Encoding Header (nginx)

前端 未结 4 1665
生来不讨喜
生来不讨喜 2021-02-05 01:47

I have an nginx server and can\'t seem to find any information on how to send Vary: Accept-Encoding headers for CSS and JS files. Does anyone have info about this?

Thank

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-05 02:13

    Simple. In Nginx conf:

    vim /etc/nginx/nginx.conf
    

    Add the following near the bottom under the section:

        ##
        # Gzip Settings
        ##
    
        gzip on;
        gzip_disable "msie6";
    
        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    

    Just uncomment the gzip_vary on; parameter and restart or reload nginx service:

    service nginx restart
    

    This should fix the issue. If you are running an old version of nginx, you may need to enable gzip on;, as this is required for the vary header to work.

    I hope this helps. FYI, this applies to all server/site conf files unless overwritten in their own respective server blocks. server {}

    Source info for nginx, apache and IIS: https://www.maxcdn.com/blog/accept-encoding-its-vary-important/

提交回复
热议问题