Website performance is the most critical factor for ranking, user engagement, and much more. There are many things to make a website faster and one of them is compression. Compressing files not only makes a website faster, but it also reduces your web hosting bills as small files need less bandwidth.
If you want to squeeze more performance from your server, you can even configure FastCGI cache along with Gzip. Here is a complete tutorial on how you can configure FastCGI cache on your server.

If you are using Nginx as your website, you can take the benefit of the gzip module. Gzip compresses the files on the fly and as the files reach the browser, they get decompressed without any loss. Which offers better performance.
What is GZIP?
Gzip is a module that comes pre installed with Nginx. Administrators use this to boost the performance of the website. Gzip compresses the website elements and when any visitor visits your website, the compressed data is sent to visitor’s device and then unzipped. As we all know compress data use less bandwidth which significantly improves website speed.
Another benefit to use Gzip is that it reduce bandwidth cost. Let’s suppose you a website with serves ~500kb of data when a user visits. Now, if you have enabled gzip, the data will be compressed and thus your server will send lesser amount data let’s say ~300kb. Which means you will have to pay for 300kb of transferred data only. If you have millions of visitors, you can save a lot of money on your bandwidth.
In this Tutorial
In this tutorial, we will learn how to enable gzip in Nginx on Ubuntu
Prerequisites
- Ubuntu server with initial configuration done
- A sudo user
- Ubuntu server with LEMP configured. If you don’t have one, follow our guide to install and configure LEMP in Ubuntu.
How to Configure Gzip compression in Nginx
1. Open nginx.conf file
$ sudo nano /etc/nginx/nginx.conf
2. Scroll down to gzip settings and you will find
##
# `gzip` Settings
#
#
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
3. Change it to
##
# `gzip` Settings
#
#
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types
application/atom+xml
application/geo+json
application/javascript
application/x-javascript
application/json
application/ld+json
application/manifest+json
application/rdf+xml
application/rss+xml
application/xhtml+xml
application/xml
font/eot
font/otf
font/ttf
image/svg+xml
text/css
text/javascript
text/plain
text/xml;
Note
No need to add JPEG, JPG, PNG, or any other image type because you can upload the compressed one using various tools available. Adding these will only consume server resources without having any considerable effect.
Press ctrl+x then “y” and hit the “Enter” key to save the file.
4. Compile Nginx to check errors
$ sudo nginx -t
If it is correct, you will get the following message
"nginx: the configuration file /etc/nginx/nginx.conf syntax is ok"
"nginx: configuration file /etc/nginx/nginx.conf test is successful"
5. Restart Nginx
$ sudo systemctl restart nginx
It’s done. You have enabled the gzip compression in Nginx on Ubuntu.
Conclusion
Gzip must be used by web administrators as it not only makes your website fast, but it also saves a lot of bandwidth.
Leave a Reply