How to enable GZIP compression in Nginx

03 Mar 2018 1 80  0


It is important to optimize your website to ensure that it is as fast as possible; website load time has a big impact on user experience and search engines such as Google consider the load time of a site as a ranking factor. SSD powered VPS is fast but not necessary when settings options such as Gzip compression in Nginx can also speed up your page load times.

In the following tutorial, we will teach you how to enable Gzip compression in Nginx.

We are going to use a method which will improve your website’s transfer speed by reducing the size of its files with compression. This can also reduce the bandwidth used and can help you get slightly cheaper if you use a hosting plan with fewer resources.

We will be using the Nginx Gzip module which will help you compress your files with the gzip compression method, with the ultimate aim of reducing the size of transmitted files by half or more.

Step 1: Enabling GZip compression

Begin by logging into your server via SSH and modifying your Nginx configuration as shown below.

[user]$ nano /etc/nginx/nginx.conf

Append or modify the lines below.

gzip on;

gzip_comp_level 2;

gzip_http_version 1.0;

gzip_proxied any;

gzip_min_length 1100;

gzip_buffers 16 8k;

gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

# Disable for IE < 6 because there are some known problems

gzip_disable "MSIE [1-6].(?!.*SV1)";

# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6

gzip_vary on;

Try out the configuration and correct any errors. Some are shown here.

nginx -t

Restart Nginx and confirm that Gzip is working correctly.

service nginx restart

You can verify that the Gzip compression is working Nginx by simply executing the curl command shown below.

[user]$curl --header "Accept-Encoding: gzip,deflate,sdch" -I

HTTP/1.1 200 OK

Server: nginx

Date: Fri, 14 Apr 2017 09:59:38 GMT

Content-Type: text/html; charset=UTF-8

Connection: keep-alive

Keep-Alive: timeout=60

Link: <>;

Content-Encoding: gzip

If the message ‘Content-Encoding: gzip’ shows up, it means that your page was served and uses the Nginx gzip module.


There are many online Gzip checkers to choose from and use in order to test whether Gzip was enabled; the curl utility check and other online tools allow you to do this.

Your server should now be properly configured to use gzip compression, making your website noticeably quicker.


Add a comment

Leave a Reply