Tutorials

Enable Gzip Compression on Nginx Server

Enabling Gzip compression lets your page load faster and saves bandwidth usage. This easy to follow, step-by-step tutorial is show you how to enable Gzip compression on a Nginx server running on Ubuntu 14.04 and test if it working. Earlier this week I have written a post “Optimize Compress JPEG, PNG Images on Ubuntu Server“. And, this post also falls in that same category as optimizing and performance improvement of a server. You also need this for your site’s SEO and it is very easy to enable this option on your Nginx server.

Enable Gzip Compression

To enable Gzip compression on Nginx server we need to open & edit /etc/nginx/nginx.conf file. Run the following command on your terminal to edit the configuration file. I use nano to edit files, you can choose your own text editor, just change the name.

sudo nano /etc/nginx/nginx.conf

Now, scroll down and you may find the Gzip section commented out with # in the beginning of the line. Just uncomment the sections and Gzip should be working. Or just add the following in the conf file.

##
# 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 
 application/atom+xml 
 application/javascript 
 application/json 
 application/rss+xml 
 application/vnd.ms-fontobject 
 application/x-font-ttf 
 application/x-web-app-manifest+json 
 application/xhtml+xml 
 application/xml 
 font/opentype 
 image/svg+xml 
 image/x-icon 
 text/css 
 text/plain 
 text/x-component 
 text/xml 
 text/javascript;

Save and exit the file. Next step is to check for errors and restart Nginx. Use the following command to check of errors.

sudo nginx -t

If the output is like below, your configurations are correct.

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Now restart Nginx for your changes to take effect using the following command.

sudo service nginx restart

How to test if Gzip is working on your site?

Use the following command to check if Gzip is working on your site or on Nginx server. Change the domain name or url that you want to test.

curl –header “Accept-encoding: gzip,deflate” -I https://techloverhd.com

If it is enabled and working you should see the result like below.

HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
Date: Sun, 27 Mar 2016 20:36:41 GMT
Content-Encoding: gzip

The last line shows that Gzip is working for this site. Also you can test online on GTmetrix. Hope you enjoyed this tutorial and successfully enabled gzip compression on your site / server. There are more tutorials to explore on this site.

TLHD

Tech blogger, web developer. Using Android from January 2009 when I got my first T-Mobile G1. Since then used a handful amount of Android smartphones and tablets. Also, rooting and using custom ROM & MODs on my phones and tablets. Photography is my passion along with Cryptocurrency. Taking pictures with my Samsung NX1 & Canon 70D during free times. Enjoy reading anything interesting happening with technology. Currently using a Galaxy S7 Edge, OnePlus 3, Nexus 5X, Galaxy Tab PRO 12.2.

Share
Published by
TLHD

Recent Posts

How to Send Komodo or Any Smart Chain Funds from Your Address Without Rescanning the Wallet?

Rescan can take long time to finish if you have thousands of transactions in… Read More

4 years ago

UK Granted Huawei A Limited Role In 5G Network

The British government has introduced that it will continue to give Huawei minimal role… Read More

4 years ago

Use Komodo’s DEXP2P Tech for Live Streaming [How-to]

Introduction Komodo's lead developer/founder James Lee "jl777" recently started working on an exciting new tech… Read More

4 years ago

AtomicDEX Mobile Decentralised Exchange is Out for Public Beta Testing

Komodo, the pioneer of decentralised cross-chain Atomic Swap has released their new version of mobile… Read More

5 years ago

How to Check Your VerusCoin Mining Balance, Hash Power & Estimated Average Time to Mine Block

This script and guide is for users who checks their VerusCoin mining node often and… Read More

6 years ago

Claim BTG and Convert to BCH in Quick & Easy to Follow Guide

This is a step-by-step guide to claim your Bitcoin Gold (BTG) and convert them into… Read More

6 years ago