gzip nginx - not working on multisite server but does from localhost

Posted June 14, 2017 3.8k views
Configuration ManagementUbuntu 16.04

I ran through the tutorial here -

and it says to add test files which go here

sudo truncate -s 1k /usr/share/nginx/html/test.css

then test like this

curl -H "Accept-Encoding: gzip" -I http://localhost/test.css

It seems localhost going here /usr/share/nginx/html/ ok that is fine…

And here it works! BUT on my actual server location here


I get gzip not working.

I have tried enabling gzip in the sites-available nginx server block config like this
“`gzip on;
gzipminlength 1100;

It's not clear if these commands should go in the location blocks or higher level server block. I tried both anyway but both don't seem to work..

BUT if the root gzip is working for the tutorial on my server why is it not working in my website...

Thanks for ideas.
 I am wondering if it is because the domain isn't working yet and am testing the live ip address and because of this it is ignored? But if that were true the default SHOULD be working?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

1 answer


The actual GZIP configuration would go in /etc/nginx/nginx.conf within the http block. For example,

http {

    gzip on;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";
    gzip_static on;
    gzip_min_length 1400;
    gzip_buffers 32 8k;
    gzip_http_version 1.0;
    gzip_comp_level 5;
    gzip_proxied any;
    gzip_types text/plain text/css text/xml application/javascript application/x-javascript application/xml application/xml+rss application/emacscript application/json image/svg+xml;


That’s example configuration from one of my custom builds, so you would need to change the value of gzip_min_length to match the minimum size of the file you want to gzip.

That said, if you had set gzip_min_length 1100; and your file is only 1K, then it won’t be gzipped as it doesn’t meet the minimum – it’s 100 bytes short.

Submit an Answer