GZip Contents on Nginx

Compressing the contents reduces the size of it thus reducing the amount of data to be transfer which results in faster load time which is equal to happy users.


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.


Wow ! you have someting to tell us. That's great! Please keep in mind that comments are moderated, we employ rel="nofollow" for links, avoid using a spammy word or a domain in name field, it might end up as a Spam. Thanks for reading.

Last 5 Articles

All Articles >

  1. Mitigating Risks In Custom Software Development

  2. Container Security to Secure Microservices

  3. Strategic Messaging

  4. URL Shortener in Django

  5. MySQL as Database Option


News Letter

Subscribe to our email newsletter for useful tips and valuable resources, sent out every new article release.