Peter Stuifzand

Nginx and gzip

I was trying to find some ways to increase the speed of my webshops, because speed matters.

I did this by using the YSlow Firebug add-on. It told me that I didn’t gzip some of my static files. That seemed strange to me because I already enabled gzipping in my nginx.conf.

I used curl and Firefox to find out if my files where gzipped. It seemed they weren’t. So I changed my gzip settings in nginx.conf to the following on my development server. (Source).

# output compression saves bandwidth
gzip  on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

# make sure gzip does not lose large gzipped js or css files
# see http://blog.leetsoft.com/2007/7/25/nginx-gzip-ssl
gzip_buffers 16 8k;

# Disable gzip for certain browsers.
gzip_disable "MSIE [1-6].(?!.*SV1)";

This in itself apparently didn’t enable gzip compression. So I had to look further. It seemed that gzip compression won’t be shown for files which are already cached. By disabling the cache for a bit I saw that my files were gzipped, but that it just wasn’t shown. Again a problem solved.

© 2023 Peter Stuifzand