Configure HTTP/2 in Nginx for Better Performance on Ubuntu 20.04
HTTP/2 is a modern upgrade to the HTTP protocol that significantly improves website performance and reduces server load. It achieves this by allowing multiple simultaneous requests over a single TCP connection, which speeds up content delivery and reduces latency. Faster load times not only enhance user experience but can also contribute to better search engine rankings. In this tutorial, we’ll walk you through the process of enabling and configuring HTTP/2 in the Nginx web server on Ubuntu 20.04.
In the Serverspace you can create a server with already installed app "Nginx".
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.
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.
Another way to check it is to use this service: https://tools.keycdn.com/http2-test.
Conclusion
Enabling HTTP/2 in Nginx on Ubuntu 20.04 is a simple yet powerful way to improve your website’s performance, reduce server resource usage, and enhance user experience. By allowing multiple parallel requests over a single connection, HTTP/2 dramatically speeds up content delivery — an important factor for both users and search engine rankings. With just a few configuration steps and HTTPS support, your site can take full advantage of modern web standards. Serverspace also offers ready-made servers with Nginx preinstalled, making the setup process even faster.
FAQ
- Q: Do I need HTTPS to use HTTP/2?
A: Yes. Most modern browsers require HTTPS to enable HTTP/2. Make sure your site has a valid SSL/TLS certificate. - Q: How can I check if HTTP/2 is enabled?
A: You can use the curl -I https://your-domain.com command or test your site via online tools like KeyCDN HTTP/2 Test. - Q: What if my Nginx version doesn't support HTTP/2?
A: You need to update Nginx to a version that supports HTTP/2 (version 1.9.5 or higher). Use apt update && apt upgrade to update your packages. - Q: Will enabling HTTP/2 break my existing configuration?
A: No, adding http2 to the listen directive is a non-breaking change as long as your server uses HTTPS and the rest of the configuration is valid. - Q: Can I enable HTTP/2 for multiple domains on the same server?
A: Yes, just make sure each virtual host that uses HTTPS also includes the http2 flag in its listen 443 ssl http2; line.


