How To Enable Gzip Compression on Nginx CentOS

Nginx is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet. It is more resource-friendly than Apache in most cases and can be used as a web server or a reverse proxy. So today we’re going to learn how to setup enable Gzip compression on Nginx on CentOS 6 or 7. Compressing your scripts and images is a good idea to optimize your website’s load times.

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. In this post, I will talk about an easy way to enable GZIP compression on nginx servers. It’s really not that difficult. Let’s start with Nginx.

Enable Gzip Compression on Nginx

Step 1. Configure nginx.conf (/etc/nginx/nginx.conf)

gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
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;
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_vary on;

Step 2. Now, you simply need to restart your server.

 service nginx restart

If you wish to test if GZIP is enabled, use this command:

 curl -H "Accept-Encoding: gzip" -I https://wpcademy.com

With that file now in place, restart your server and you will now be serving site assets with gzip compression. Google takes site speed into account when ranking and placing your sites in their search engine so do your users a favor and strive for the fastest site possible, especially for mobile users.

Congratulation’s! You have successfully enable Gzip on Nginx. Thanks for using this tutorial for enable gzip compression Nginx on Linux system. For additional help or useful information, we recommend you to check the official Nginx web site.

Leave a Reply