If you use NGINX, you probably care about performance, and one of the easiest website performance wins is to Gzip http requests. Gzip can not only increase the speed of your website, but also save bandwidth. I’ll show you how to Gzip http requests with your NGINX server in this post.

Gzip is a compression tool with many uses, including compressing the output of your webserver. If you are running NGINX on Linux, Gzip is already installed.

You can add these directives in the http, server, or location blocks of your NGINX config file, depending on your needs.

gzip on;
gzip_proxied any;
gzip_types text/plain text/css text/javascript text/xml application/xml application/xhtml+xml application/xml+rss;
gzip_disable "MSIE [1-6].";

Code breakdown:

  1. gzip – Enable Gzip
  2. gzip_proxied – Gzip all requests. See the list of parameters here – gzip_proxied
  3. gzip_types – Types of content to gzip. Note that text/html is enabled by default, and will cause a warning if you add it here.
  4. gzip_disable – Prevent compression to old versions of Internet Explorer.

Other Gzip Settings

There are a few other settings that can be used that I have not added here. Above is what I use, but you can customize it further. I don’t see any reason to change these from the default values, so I leave them alone.


You can increase the level of compression, for the price of server work. The default level is 1, which is what most people use. It is generally agreed that raising gzip_comp_level is a performance anti-pattern, as it takes longer than the savings gained by the extra compression.


With this, you can set the minimum size file in bytes to gzip. The default is 20 bytes.

There are even more settings, but I don’t understand them very well, and based on the documentation they look likely to cause bugs, so I have left them out.

If you want to read more about Gzipping with your NGINX server, check out the official documentation.