By Calvin Crane
I ran through the tutorial here - https://www.digitalocean.com/community/tutorials/how-to-add-the-gzip-module-to-nginx-on-ubuntu-14-04
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
/var/www/sites.co/html/test.css.
I get gzip not working.
I have tried enabling gzip in the sites-available nginx server block config like this
gzip_min_length 1100;
etc
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?
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!
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.