How to Configure Compression in Nginx Server

Where necessary, you may need to have access to a VPS server so you can follow how to implement the steps in this article.  You can get a cheaper VPS Server from Contabo with 4vCPU cores, 8GM RAM, and 32TB Bandwidth for less than $5.50 per month. Get this deal here now

Table of Contents

Cloud VPS S

$5.50 Monthly
  • 4 vCPU Cores | 8GB RAM


$15.50 Monthly
  • 6 vCPU Cores | 16GB RAM


$17.50 Monthly
  • 8 vCPU Cores | 24GB RAM

Compression reduces the size of data transmitted between the server and clients, resulting in faster load times and reduced bandwidth usage. In this article, we’ll explore how to configure compression in Nginx with practical command examples.

Before configuring compression, it’s essential to ensure you have a version of Nginx that supports the necessary modules. Execute the following command to check your Nginx version:

nginx -v

Compression support in Nginx has been available for quite some time, and it’s a standard feature in modern versions. However, to be precise, the ngx_http_gzip_module module, that is responsible for Gzip compression, was introduced in Nginx version 0.6.24.

If you are using a version earlier than 0.6.24, it’s strongly recommended to upgrade to a newer version to benefit from essential features, security updates, and improvements.

Open the Nginx configuration file

Use your preferred text editor to open the Nginx configuration file. The default path is often /etc/nginx/nginx.conf or /etc/nginx/conf.d/default.conf. Execute the following command to open the file:

sudo nano /etc/nginx/nginx.conf

Locate HTTP Block

Within the configuration file, locate the http block. This is where server-wide settings are typically configured.

Add Gzip Configuration

Insert the following lines within the http block to enable Gzip compression:

http {
    gzip on;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_disable "msie6";
    gzip_vary on;
  • gzip on: Enables Gzip compression.
  • gzip_types: Specifies the file types to be compressed.
  • gzip_disable "msie6": Disables compression for older Internet Explorer versions.
  • gzip_vary on: Adds the “Vary: Accept-Encoding” header to the response.

Save the changes to the configuration file and exit the text editor.

Test Nginx Configuration

Before restarting Nginx, it’s a good practice to test the configuration to catch any syntax errors. Execute:

sudo nginx -t

If the test is successful, proceed to restart Nginx:

sudo service nginx restart

Verifying Compression

To verify that compression is working, you can use various online tools or browser developer tools. One popular tool is GzipWTF, where you can input your website URL and check if compression is active.


Configuring compression in Nginx is a simple yet effective way to enhance your web server’s performance. Reducing the size of the data transmitted can significantly improve page load times and overall user experience.

Hire us to handle what you want

Hire us through our Fiverr Profile and leave all the complicated & technical stuff to us. Here are some of the things we can do for you:

  • Website migration, troubleshooting, and maintenance.
  • Server & application deployment, scaling, troubleshooting, and maintenance
  • Deployment of Kubernetes, Docker, Cloudron, Ant Media, Apache, Nginx,  OpenVPN, cPanel, WHMCS, WordPress, and more
  • Everything you need on AWS, IBM Cloud, GCP, Azure, Oracle Cloud, Alibaba Cloud, Linode, Contabo, DigitalOcean, Ionos, Vultr, GoDaddy, HostGator, Namecheap, DreamHost, and more.

We will design, configure, deploy, or troubleshoot anything you want. Starting from $10, we will get your job done in the shortest time possible. Your payment is safe with Fiverr as we will only be paid once your project is completed.