How to Install Nginx with HTTP/2 Support on Ubuntu
Nginx is a high-performance web server and reverse proxy, widely used for hosting websites and applications. HTTP/2 significantly improves web performance by enabling multiplexing, header compression, and other optimizations. In this guide, we’ll cover how to install Nginx on Ubuntu with HTTP/2 support.
Step 1: Update System Packages
Before installing Nginx, update your package list and system packages to ensure you have the latest software versions.
sudo apt update && sudo apt upgrade -yStep 2: Install Nginx
Ubuntu’s default repositories include Nginx, so you can install it using
apt:
sudo apt install nginx -yOnce the installation is complete, verify that Nginx is running:
sudo systemctl status nginxIf Nginx is not active, start it with:
sudo systemctl start nginxStep 3: Enable HTTP/2 Support in Nginx
To enable HTTP/2, modify the Nginx configuration file:
sudo nano /etc/nginx/sites-available/defaultFind the following line:
listen 443 ssl;Modify it to include
http2:
listen 443 ssl http2;Save the changes (
CTRL + X, then
Y, and
Enter).
Step 4: Obtain an SSL Certificate
HTTP/2 requires SSL/TLS, so you need a valid SSL certificate. The easiest way is to use Let’s Encrypt with Certbot:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginxFollow the prompts to generate and install the certificate.
Step 5: Restart Nginx and Verify
After enabling HTTP/2, restart Nginx to apply the changes:
sudo systemctl restart nginxVerify that HTTP/2 is working with:
curl -I --http2 https://yourdomain.comYou should see the
HTTP/2response header.
Conclusion
You have successfully installed Nginx with HTTP/2 support on Ubuntu. Your website will now benefit from improved performance and faster page loading times. If you need to make further optimizations, consider enabling caching, compression, and fine-tuning your Nginx configuration.


