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

June 14, 2017 65 views
Configuration Management Ubuntu 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?
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.

  • Thanks - it seems to be a lot better since I now have the actual domain name pointing. The actual domain is and it looks ok to me.

    • @landed

      No problem at all -- running a check on my end, all looks good, so you should be good to go. If you happen to run in to any other issues, feel free to tag me and let me know!

Have another answer? Share your knowledge.