How To Enable HTTP2 in NGINX

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello, friends. On this day, I have another trick about Nginx. In short, today, you will learn how to enable HTTP2 in Nginx.

HTTP2 is the natural evolution of HTTP. Thanks to it, we will have an improvement in the speed of response due to its architecture that allows with a connection to make several requests and responses.

Another interesting aspect of HTTP2 is that it eliminates the sending and receiving of redundant information. In addition to this, everything is done securely so that the Internet experience becomes more efficient.

For these and more reasons is that many sysadmin and webmasters choose to enable this protocol in all their configurations. Today we will do the same using Nginx.

Some considerations

To perform this tutorial, we need to have Nginx installed and configured correctly. In addition to this, we will use a user with sudo or root permissions.

In addition to this, it is required that the version of Nginx is higher than 1.9.5 and that you have some minimal terminal skills.

So, let’s go for it.

How to enable HTTP2 in Nginx

If you want to enable HTTP2 in Nginx globally, then we have to modify the configuration file, which is /etc/nginx/nginx.conf.

sudo nano /etc/nginx/nginx.conf

But in case we have many configurations for each site on our server, then we have to edit each of these files. An example of how these files look like is.

sudo nano /etc/nginx/sites-enabled/domain.conf

In this case, I show you that I use nano but you can really use any text editor.

Once you have started editing, you will need to check that in the server section you have SSL enabled via the listen directive. If this is true, just add HTTP/2 like this.

server { 
    listen 443 ssl http2; 
    ssl_certificate ...
    ssl_certificate_key ...
 }

Now save the changes and close the editor.

Now you have to check that the Nginx syntax is correct.

sudo nginx -t

If there is no error, you can restart Nginx by executing

sudo systemctl restart nginx

If you want to check the changes, you can use some external tool. One of the best for this is KeyCDN where you can easily do the check.

I hope it helped you.

Conclusion

In this post, we have shown you how to enable HTTP2 in Nginx quickly, easily and without complications.

Thanks for reading, and I hope it has served you in your projects.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook