Gzip compression with NGINX

Gzip compression with NGINX

20 Apr 2016 4 min read

We often do some server administration job for the server we work on and host our corporate and client sites which are at development.  One day we decided to turn GZIP compression on at the server to speed up the HTTP packets downloading.  Although it seemed to be a trivial task, but it turned out that a good manual, that could clearly explain how to do it for Nginx on Centos 7, was difficult to find.

Eventually after we have successfully coped with this problem, we decided our experience is going to be useful and set up such a manual.

ngx_http_gzip_module – it’s such a filter that reduce size of transmitted data to twice or more by compressing response with Gzip.

Activate GZIP on Nginx in this file   /usr/local/etc/nginx/nginx.conf

http {
...
# Enable / Disable the gzip compression
gzip on;
# The minimum size of compressing file, in bytes
gzip_min_length 1000;
# Set the buffer size for all proxy requests
gzip_proxied any;
# MIME types that should be compressed
# gzip_types text/plain text/html text/xml application/xml application/x-javascript text/javascript text/css text/json;
# If there are warnings, like "duplicate MIME type text/html", then you should exclude text/html
#gzip_types text/plain text/xml application/xml application/x-javascript text/javascript text/css text/json;
# It is forbidden to use Gzip compression for IE6
gzip_disable "msie6";
# Level of Gzip compression
gzip_comp_level 8;
...
}

Be sure restart the Nginx.

Now if you want to test how Gzip compression is working on Nginx, please follow next.

[my@lan ~]$ curl --header "Accept-Encoding: gzip,deflate,sdch" -I http://www.scalescale.com/tips/nginx
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 26 Feb 2013 15:41:38 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
X-Pingback: http://www.scalescale.com/tips/nginx/xmlrpc.php
Content-Encoding: gzip

We hope you would find it useful!

ERP development final cta

Get a Custom Solution with Web Design Sun

At Web Design Sun, we specialize in building web applications for clients in every business and industry.  If you’re interested in custom applications for your business, contact us today.

Contact us today to get started

More From Blog

How To Merge Git branch To Master And Handle Merge Conflicts

How does Git decide which type of merge should be applied, and to handle with merge conflict that may occur in case of a 3-way merge?
30 Nov 2017 10 min read

7 Web Design Tendencies for 2017

As 2017 is already here, it’s high time we all found out the major web design tendencies that will prevail during the year.
6 Mar 2017 11 min read

8 Web Development Trends to Watch Out for in 2023

Stay ahead of the game in web development with our guide to 8 key trends for 2023. From artificial intelligence and machine learning to serverless computing and the Internet of Things, this blog post covers the technologies and techniques that you need to know to create the best possible user experience.
6 Jan 2023 8 min read