How to Configure HTTP/2 in Nginx on Ubuntu 20.04
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.
Necessary conditions:
- The Nginx web server is installed and its basic configuration is performed;
- Your site uses the HTTPS protocol. Most web browsers require an encrypted connection to enable HTTP/2.
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.
Configuring the HTTP/2 in Nginx
Open the configuration file of your virtual host.
Find this line in it:
Add http2 here:
If you see the line, starting with:
Then add http2 in it too.
Save and close the file, and check the configuration for errors.
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:
Now enter this command with your FQDN in it:
Output:
...
This means that your site is currently using HTTP/2.
Another way to check it is to use this service: https://tools.keycdn.com/http2-test.