On fresh installation of Nginx, let's check whether the gzip has been enabled?

$curl -H "Accept-Encoding: gzip" -I https://techglimpse.com
 HTTP/1.1 200 OK
 Server: nginx
 Date: Wed, 2 Aug 2018 11:14:25 GMT
 Content-Type: text/html; charset=UTF-8
 Connection: keep-alive
 ETag: W/"52f49928-fe89"
 Accept-Ranges: bytes

From the above result, there is no mention of compression!

Enable gzip compression on Nginx server

Let’s configure Nginx to compress not only HTML files, but also other file formats like, Images, CSS, JS etc., that can benefit from compression.

Open the Nginx configuration file in your favorite text editor and insert the below code.

# vim /etc/nginx/nginx.conf

 # reduce the data that needs to be sent over network
 gzip on;
 gzip_vary on;
 gzip_buffers 16 8k;
 gzip_comp_level 6;
 gzip_min_length 1000;
 gzip_proxied expired no-cache no-store private auth;
 gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
 gzip_disable msie6;
 gzip_http_version 1.1;

For the new configuration to take effect, test the configuration for errors and then restart Nginx.

# nginx -t

# systemctl restart nginx

Verify Gzip compression

$curl -H "Accept-Encoding: gzip" -I https://techglimpse.com
HTTP/1.1 200 OK
Server: thing
Date: Wed, 2 Aug 2018 12:00:46 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
Link: <https://techglimpse.com/wp-json/>; rel="https://api.w.org/"
X-Cache: MISS
Content-Encoding: gzip

Google gives importance to website’s load time when ranking and placing your website in search results upon your competitors. Enabling gzip will increase organic traffic.


Was this answer helpful? 0 Users Found This Useful (0 Votes)