Introduction
In this article, we will learn How to enable GZIP compression for NGINX on Ubuntu 18.04. Before enabling the GZIP compression lets first know more about the GZIP and compression.
What is GZIP Compression?
GZIP is a way to compress data. It is commonly used for web apps and websites. HTTP protocols have an ability to use GZIP compression. When we request a page by entering any URL in the browser, the web server compresses the data based on the request and send back it to the browser. At the browser, data will decompress and displays it to the end user. We are assuming GZIP compression is enabled at the server. Now you may ask why we need to use GZIP compression.
Why use GZIP Compression?
To understand the importance of the GZIP compression we created a sample page. It is available on our server web root directory. In this sample page, we are using the following files.
- CSS: A CSS file with size approx 4 MB
- JavaScript: A JavaScript file with size approx 4 MB
- Image: An image file with approx size 5.5 MB
- HTML Content: The HTML content for the sample page is with the size is around 4 MB.
How to enable GZIP Compression for NGINX on Ubuntu 18.04?
We are using Google Cloud Compute Engine VM Instance. To apply any changes, we need to use the SSH panel. Launch the SSH panel. We have already checked headers for PHP, CSS, and the JavaScript file. You can also check the GZIP status using SSH panel. Following is the command to check it in SSH panel.
Code
curl -H "Accept-Encoding: gzip" -I http://35.193.211.90/index.php
curl -H "Accept-Encoding: gzip" -I http://35.193.211.90/index.html
curl -H "Accept-Encoding: gzip" -I http://35.193.211.90/Test1.js
curl -H "Accept-Encoding: gzip" -I http://35.193.211.90/Test1.css
curl -H "Accept-Encoding: gzip" -I http://35.193.211.90/lemon.jpg
If for any of the above commands if you get an entry for "Content-Encoding: gzip" then GZIP compression is enabled for that file type.Code
sudo nano /etc/nginx/nginx.conf
In the nginx.conf file search for the gzip settings.- application/vnd.ms-fontobject
- application/x-font-ttf
- font/opentype
- image/svg+xml
- image/x-icon;
Posted from my blog
Warning! This user is on my black list, likely as a known plagiarist, spammer or ID thief. Please be cautious with this post!
If you believe this is an error, please chat with us in the #cheetah-appeals channel in our discord.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit