We’ll show you, How to enable GZIP compression in Nginx. Lately, it’s all about optimizing your website and making it as fast as possible. Especially since search engines like Google consider page load time as a ranking factor. And, of course, the load time is a huge factor in user experience.
Aside from using a fast, SSD-powered VPS, you can also do some other tweaks and settings to speed up your website, like enabling gzip compression in Nginx.
Here we’ll discuss one method that will increase the transfer speed by reducing the size of the files with compression. This method will also bring up the benefit of reducing the bandwidth that is used in this process and will make the hosting cheaper to the owner (ie, you can use a hosting plan with fewer resources. The best part about – it’s easy to do and it will only take you a few minutes.
In this article, we’ll share with you how to do the above with the Nginx gzip module. As it is stated this module will help you to compress your files with the gzip compression method. It is known that this method will reduce the size of the transmitted files by half or in some cases even more.
How to enable it?
SSH into your server, and edit your nginx configuration:
[user]$ nano /etc/nginx/nginx.conf
Add or edit the following lines:
Test the configuration and fix errors (if any are shown):
Restart Nginx and verify that gzip is working properly.
service nginx restart
How to test if gzip compression is working in Nginx? Run the following curl command:
[user]$curl --header "Accept-Encoding: gzip,deflate,sdch" -I http://your-domain-name.com/ HTTP/1.1 200 OK Server: nginx Date: Fri, 14 Apr 2017 09:59:38 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive Keep-Alive: timeout=60 Link: <http://your-domain-name.com/wp-json/>; Content-Encoding: gzip
If you see
Content-Encoding: gzip, that means your page was served using the Nginx gzip Module.
Another way to test this is using an online gzip test. There are many “gzip checkers” out there, so use whichever one you want. You can even check and verify if gzip is enabled using multiple methods, including curl and several online tools.
That’s it. Your server should now be configured to use gzip compression and your websites should be noticeably faster.
Of course, you don’t have to do any of this if you use one of our Service Configuration & Optimization Services, in which case you can simply ask our expert Linux admins to enable gzip compression for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.