How to enable gzip compression with NGINX

How to enable gzip compression with NGINX

In this article, we will see How to enable gzip compression with NGINX to improve the performance of our web application.

Go to the /etc/nginx/nginx.conf

First you need to find

gzip on;

and comment on it using Hash(#), like below:

#gzip on;

Then adding below code snippets below above code:

gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";

Here is a line-by-line explanation of the configuration:

gzip on;

Will Activates gzip compression

gzip_vary on;

instructs proxies to store both the regular and gzipped versions of a resource.

gzip_min_length 1024;

It will Nginx to not compress anything that is lower than the specified size.


This command will instruct to compress data even for clients that are connecting via proxies.

In our case,  we’re enabling compression if: a response header includes the “expired”, “no-cache”, “no-store”, “private”, and “Authorization” parameters


Here we can list out the types of files that need to be compressed


Here we are telling Nginx to disable compression for Internet Explorer versions 1-6

Subscribe to our Newsletter

Stay up to date! Get all the latest posts delivered straight to your inbox.

If You Appreciate What We Do Here On TutsCoder, You Should Consider:

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Leave a Comment