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

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_min_length  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. [Edit] 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?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.


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.