GZip compression with Nginx

system nginx gzip compression
Reading time: 1 minute, 0 seconds

When you reviewing your website with Google Pagespeed Insights, you could have the following error :

To fix this problem, a little modification of Nginx configuration is necessary :

In /etc/nginx/nginx.conf file or in new file /etc/nginx/conf.d/gzip.conf, add the following code :

gzip on; #Enables gzipping of responses
gzip_proxied any; #Enables compression for all proxied requests.
gzip_types text/plain text/xml text/css application/x-javascript; #Enables gzipping of responses for the specified MIME types in addition to “text/html”.
gzip_vary on; #Enables or disables inserting the “Vary: Accept-Encoding” response header field
gzip_disable "MSIE [1-6]\.(?!.*SV1)"; #Disables gzipping of responses for requests with “User-Agent” header fields matching any of the specified regular expressions.

and restart the Nginx service :

sudo service nginx restart

Now all your website assets have gzip compression.

Next Post Previous Post