gzip is a file format and a software application used for file compression and decompression. On the web its used to compress contents before serving from server and is decompressed by client before use. This saves bandwidth and improves render time which in-turn brings happy faces.

gzip compression can be done for text data CSS, JavaScript, XML files. However, never enable gzip compression for images or any kind of binary data.

On an apache server its straight forward using htaccess, Nginx isn’t a mammoth task normally involves uncommenting lines in configuration file. I had written about Compression of web pages a few years back explaining various methods to enable compression of different server.

Compression on Nginx

Open up the Nginx configuration file which is /etc/nginx/nginx.conf. By default the the rules to enable Gzip are commented out with # , you just have to uncomment those lines.


##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

gzip_types defines the type of files to be compressed.

This enables Gzip on all the sites you host on the server, you can over ride the settings on site configuration in sites-available directory.