TechLoverHD

Adaptable Knowledge of Technology

  • Android
  • Apps
  • Games
  • Devices
    • Phones
    • Tablets
    • Gadgets
    • Smart & HD TV
  • OS
    • Ubuntu
    • Windows
  • Tutorials
  • News
You are here: Home / Tutorials / Enable Gzip Compression on Nginx Server

Enable Gzip Compression on Nginx Server

27th March 2016 by TLHD

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 on Nginx

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.

Filed Under: Tutorials Tagged With: Gzip, Nginx, Server, Ubuntu 14.04

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 192 other subscribers.

Follow TechLoverHD

Categories

  • Apps (101)
  • Cryptocurrency (11)
  • Devices (190)
    • Gadgets (34)
    • Smart & HD TV (13)
    • Smartphones (123)
    • Tablets (28)
  • Games (1)
  • News (76)
  • OS (73)
    • Android (54)
    • Firefox OS (2)
    • Ubuntu (8)
    • Windows (9)
  • Photography (7)
  • Tutorials (61)

Recent Posts

  • How to Send Komodo or Any Smart Chain Funds from Your Address Without Rescanning the Wallet?
  • UK Granted Huawei A Limited Role In 5G Network
  • Use Komodo’s DEXP2P Tech for Live Streaming [How-to]
  • AtomicDEX Mobile Decentralised Exchange is Out for Public Beta Testing
  • How to Check Your VerusCoin Mining Balance, Hash Power & Estimated Average Time to Mine a Block
  • Claim BTG and Convert to BCH in a Quick & Easy to Follow Guide
  • How to Claim Komodo (KMD) Reward from Ledger Nano S?
  • Lenovo ZUK Z2 – Lot of PHONE for the MONEY
  • Difference Between Samsung Galaxy A5 and Galaxy A3 2017 Model
  • Alcatel Plus 10 2in1 4G Convertible Budget Friendly Windows 10 Tablet

© Copyright 2013-020 TechLoverHD · All Rights Reserved - About Us | Contact Us | Privacy Policy | Terms of Service | DMCA Policy