HTTP/2 with Nginx

How to setup the HTTP2 with Nginx under Ubuntu 18.04 LTS

Nginx is a sturdy yet light http-server. Today we’ll tell you how to implement HTTP/2 support for your Nginx server.

Why use HTTP/2?

Previous (HTTP 1.1) version of the protocol suffers from some limitations: slow speed, a lot of requests and so on. The current version (2) is pretty good to go.

Before we start I am assuming that you already have Nginx installed and configured on your server. Let’s continue to the settings and options.

Enable SSL support for your Server

1.​ First, update your system: ​ sudo apt-get update
2.​ Then, run: ​ sudo apt-get install software-properties-common
3.​ Add universe repository: ​ sudo add-apt-repository universe
4.​ Add certbot repository: ​ sudo add-apt-repository ppa:certbot/certbot
5.​ Update the system again: ​ sudo apt-get update
6.​ Install certbot: ​ sudo apt-get install certbot python-certbot-nginx
7.​ Stop Nginx: ​ sudo service nginx stop
8.​ Obtain a new certificate: ​ sudo certbot certonly –standalone –preferred-challenges http -d
9.​ Remember or write down a certificate path.
10.​ Run sudo ​ nano /etc/nginx/sites-available/yourdomain.conf
11.​ Find the “server” block and correct it to this variant:

12. Find the second “server” block and add/update the following code:

Finally save the file. To test your changes call: nginx -t

If it’s OK, then restart Nginx: ​ sudo service nginx start

Use our fre HTTP/2 test to check if your site uses HTTP/2.

You’re good to go with the new SSL certificate, and HTTP/2 enabled.