Enabling GZIP compression on Nginx servers is easy and it improves application performance as well as saves bandwidth transfer.
By following below steps you can enable GZIP on your virtual private server with simple configuration changes.
First step is edit
nginx.conf file, that could be located
/usr/local/nginx/conf/nginx.conf, in most distributions.
nginx.conf file with your favorite editor. You can see that there’s already a block of settings regarding Gzip; you could always just modify those and un-comment out the lines as shown below –
# enable gzip compression
# Turns on/off the gzip compression.
# Compression level (1-9).
# 5 is a perfect compromise between size and cpu usage, offering about
# 75% reduction for most ascii files (almost identical to level 9).
# The minimum size file to compress the files.
# Set the buffer size of gzip, 4 32k is good enough for almost everybody.
gzip_buffers 4 32k;
# Compress data even for clients that are connecting to us via proxies,
# identified by the "Via" header (required for CloudFront).
# This directive let you specify which file types should be compressed, in this case plain text, js files, xml and #css.
# Enables response header of “Vary: Accept-Encoding
# end gzip configuration
Once your done with above config changes, restart or reload your server and you will now be serving site assets with gzip compression.
sudo service nginx restart
Apart from above benefits, Google takes site speed into account when ranking and placing your sites in their search engine.
To test if gzip is enabled, run:
curl -H "Accept-Encoding: gzip" -I https://arjunphp.com/
You should see content-encoding: gzip
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.