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.

Advert

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.

Comments

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. Development Environment for Django in Docker Compose

     
  2. How Online Reviews Impact Local SEO

     
  3. 3 Money-Saving Tips For Your Company

     
  4. Domain Authority

     
  5. Public Endpoint in Django Rest Framework

     

News Letter

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