How To Enable gzip With NGINX and Ubuntu 22.04

Gzip is a file compression method that reduces the size of HTML, CSS, and JavaScript files by up to 80%. Enabling gzip on your web server can significantly improve your website’s loading speed and reduce bandwidth usage. This post will guide you on how to enable gzip compression with NGINX and Ubuntu 22.04.

Step 1: Check if gzip is enabled

Before proceeding with the steps, it’s important to check if gzip is already enabled on your server. You can use the following command to check:

nginx -V 2>&1 | grep -o with-http_gzip_static_module

If you see with-http_gzip_static_module, it means that gzip is already enabled.

Step 2: Install gzip

If gzip is not already enabled, the first step is to install the gzip module:

sudo apt-get update
sudo apt-get install nginx-extras

Step 3: Configure gzip in NGINX

Next, you need to configure gzip in NGINX. Open the /etc/nginx/nginx.conf file in your favorite text editor:

sudo nano /etc/nginx/nginx.conf

Add the following lines to the file:

gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;

Save and close the file.

Step 4: Test gzip

To test if gzip is working, you can use an online tool like GTmetrix or Pingdom. Simply run a speed test for your website, and the tool will tell you if gzip is enabled or not.

In conclusion, enabling gzip compression with NGINX and Ubuntu 22.04 is a simple and effective way to improve your website’s loading speed and reduce bandwidth usage. By following the steps outlined in this post, you can enable gzip and start enjoying the benefits it offers.

Picture of admin

admin

Leave a Reply

Sign up for our Newsletter

Get the latest information on what is going on in the I.T. World.