Using Gzip with nginx on your VPS to speed up your website

Using Gzip with nginx on your VPS to speed up your website

The speed at which your website responds to various queries, both front end, and back end is very important when we consider user experience. Quick response is one of the most effective factors that can change the user experience drastically. Hence, it is very much important to keep in mind that in order to be perfect, your website should be working at the fastest speed possible. In regards to that, Gzip can be used to compress and filter the responses of the website.

The built-in module uses the Gzip compression method to compress simple text files like HTML, javascript, or CSS very easily so that transfer rate increases and more data can be sent in one go. Hence, the combination of Gzip and Nginx has the potential to increase the speed of your website many times. Keep in mind that it won’t compress the standard website files, this method is a very prominent way to make your website faster than ever.

So, let’s start step by step:-

Install the Nginx server

Using Gzip with nginx on your VPS to speed up your website

This is a very efficient, fast, and free web server software. Nginx has more than one uses as it can act as a:-

  • Load balancer
  • TCP/UDP proxy server
  • reverse proxy
  • IMAP/POP3 proxy server as well

Install the Nginx using the following steps:

1. Log in as a root user in the server

2. Update all the yum packages by using this command- # yum update.

3. After this, finalize the installation with this command- # yum install nginx

4. Now start Nginx and start accessing the server files with these commands

#systemctl start nginx

#systemctl enable nginx

5. To stop your server, use the given command- #systemctl stop nginx

6. To check where the above steps have worked or not open your browser and hit the IP. That should directly open the Nginx welcome page.

Configuring the Gzip module

Configure and enable the Gzip module by following the given steps:

1. Open your Nginx configuration file using this command- #vim /etc/nginx/nginx.conf

2. Try to locate the main server in the files and after that modify or add the given lines-

root /var/www/html;

gzip on;

gzip_types text/plain image/jpeg image/png image/css text/javascript;

Test your Nginx website

After successfully enabling the Gzip compression, you can run by using the given command-

# systemctl restart nginx

After this, you will have to open an unzipped Bootstrap file so that you can analyze the transfer speed. If in any case, the page is already opened in the browser just press F5 or hit refresh to see the changes.

After doing all this, open your “Network Requests” tab from the web developer’s tool in the browser. After that, your page should be significantly faster than before. Transferring should be increased. Always take a screenshot of the speeds before and after enabling the Gzip compression. Please keep in mind that the mentioned will be in ‘mili second’ or ‘ms’.

Points to remember

1) The compression of the files will obviously increase the load on the servers. But this very small tradeoff can be considered very easily since it will increase the speed of the website very significantly.

2) All this can be done by users who use older browsers as well since the browser will negotiate with the server long before any particular file is transferred. In any case, the browser is not able to deliver compressed files, the server will simply deliver the uncompressed files.

3) You must have the SSH access in order to set up a root user.

4) if you are installing Nginx on cPanel, then there is a possibility that you may run into some trouble with your existing apache configuration. To verify that both the Nginx and apache are working on the same port, follow the below steps after logging in WHM:-

Go to server configuration > tweak setting

Make use of the search option and try to find the apache non-SSL IP/port and set that to 8080 or any other port number other than 80. If, in any case, Gzip fails to load, reboot your system server, and add all the necessary lines mentioned above but not the part where it is written nginx.conf in step 2 part 1.

Conclusion

The speed of your website can be a very big factor when we consider the factors that affect the perfect user experience. This Gzip with Nginx can help you get much higher speeds than before while optimizing the file transfer speeds for your website. A fast and easy method to quickly increase the speed of your website

Cheap Linux VPS