Enable gzip compression

on February 26th, 2017 by Hades | No Comments »

You can use a site like gtmetrix.com to check if your site has gzip compression enabled properly.

You can use these tools:

check for gzip compression on HTML output of pages.

You can enable gzip compression for CSS and JavaScript files also. Apart from that any text data, e.g. XML files will also benefit from gzip compression. However, never turn on gzip compression on images or any kind of binary data.

Enable Gzip Compression

Most likely gzip is enabled on your server. If not, you can following codes in /etc/nginx/nginx.conf

Most important lines are gzip on and gzip_types

gzip on turns on gzip compression. Later on, you can add gzip off under a server{..} block or location{..} to turn off gzip compression for one or more sites/regions.

gzip_types is list of MIME-types for which you want to turn on compression. text/html is implied and cannot be turned off (unless you set gzip off). text/css and application/x-javascript enables gzip compression for CSS and javascript files respectively.