Serverspace Black Friday
JH
Joe Harris
December 17, 2020
Updated June 7, 2023

How to Configure HTTP/2 in Nginx on Ubuntu 20.04

Linux NGINX Ubuntu Web server

Using another OS?

Select the desired version or distribution.

HTTP/2 is an improved version of the HTTP protocol that allows you to increase the speed of the site and reduce the load on the web server. All this is possible by making multiple simultaneous requests in a single TCP connection. Increasing the speed not only improves the user experience with the site, but potentially even elevates its position in the search engine results. In this tutorial we will look at how to configure HTTP/2 in the Nginx web server on the Ubuntu 20.04 system.

In the Serverspace you can create a server with already installed app "Nginx".

Necessary conditions:

Preparing the system for HTTP/2

First, you need a fresh version of the Nginx web server to be able to enable HTTP/2. Update the packages in the system.

apt update && apt upgrade

Configuring the HTTP/2 in Nginx

Open the configuration file of your virtual host.

nano /etc/nginx/sites-available/domain-name.com

Find this line in it:

listen 443 ssl;

Add http2 here:

listen 443 ssl http2;

If you see the line, starting with:

listen [::]:443 ssl ...

Then add http2 in it too.

listen [::]:443 ssl http2 ...

Save and close the file, and check the configuration for errors.

nginx -t

Restart Nginx.

systemctl restart nginx

That's it, the HTTP/2 protocol is enabled on your website.

Check if the HTTP/2 is enabled

You can check whether HTTP / 2 is enabled directly in the command line of any Linux machine. To do this, you need to install curl. For example, for Ubuntu:

apt install curl

Now enter this command with your FQDN in it:

curl -I https://domain-name.com

Output:

HTTP/2 200
...

This means that your site is currently using HTTP/2.

Vote:
5 out of 5
Аverage rating : 5
Rated by: 3
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.