DEV Community

Ananth
Ananth

Posted on

Make your website faster with a HTTP/2 Webserver like Nginx

Websites have been around for a very long time. HTTP is the default protocol that is used in serving the web pages. The most common version used is version 1.1. and it has served us quite well the last few decades.

With the recent advances in the browser technologies, especially with the popularity of Web 2.0 features used in popular frontend Javascript frameworks, it was time to upgrade the backend server technologies also.

Limitations of HTTP version 1.1

  • Limited to single or a few handful of client requests
  • SSL/TSL certificates are optional

Advantages of HTTP/2

  • It loads pages much faster due to parallel downloads
  • More secure as it requires SSL/TSL certificate to connect
  • No frontend code changes required to take advantage of newer features on the server.

How to Enable HTTP/2 on Nginx Servers

If your website is running on Nginx webserver, it is very easy to change it to run HTTP/2.

Step 1: Edit your server config file for your website. For Linux users, it is usually found in /etc/nginx/sites-available/default.

Step 2: Find the line that reads "listen 443 ssl"

Step 3: Append the word http2 so that it now reads "listen 443 ssl http2"

Step 4: Check if the settings are correct with "nginx -t"

Step 5: If everything is ok, restart the server with "systemctl restart nginx"

Et voila!

Testing the Changes

In order to verify that your server is now running on http/2 mode, you can open the website in your browser like Chrome or Firefox. If you open the developer console and inspect the Network tab, it shows the version of the requests made to the web server.

Top comments (0)