How to Enable HTTP/2 in Nginx on Ubuntu 26.04 LTS
Turn on HTTP/2 in Nginx on Ubuntu 26.04 LTS with the current http2 directive, with the older listen syntax for 24.04 and Debian 12, plus verification.
HTTP/2 lets a browser send many requests over one TLS connection, compresses headers and removes most of the reasons for the old workarounds of the HTTP/1.1 era. Nginx has supported it for years, but the way you switch it on changed: since Nginx 1.25.1 there is a dedicated http2 directive, and the old http2 parameter of listen is deprecated. This guide enables HTTP/2 on Ubuntu 26.04 LTS with the current syntax and shows what to write on releases that still ship an older Nginx.
At the end your HTTPS site answers over HTTP/2, and you know how to verify it from the command line.
Which syntax applies to your release
| Release | Packaged Nginx | How to enable HTTP/2 |
|---|---|---|
| Ubuntu 26.04 LTS | 1.28 | http2 on; |
| Ubuntu 24.04 LTS | 1.24 | listen 443 ssl http2; |
| Debian 13 | 1.26 | http2 on; |
| Debian 12 | 1.22 | listen 443 ssl http2; |
The rule is simple: Nginx 1.25.1 and later use the directive; anything older only understands the listen parameter. Ubuntu 16.04, which older versions of this guide targeted, is long out of standard support, and there is no need any more to add a third-party repository just to get an HTTP/2-capable Nginx.
Requirements
- A server running Ubuntu 26.04 LTS (or one of the releases in the table) and a user with
sudorights. - A domain name pointing to the server. The examples use
example.com. - A TLS certificate. Browsers only speak HTTP/2 over TLS, so a plain HTTP site on port 80 cannot benefit from it.
Step 1: Install Nginx and check the version
sudo apt update
sudo apt install nginx
Check which version you have and that the HTTP/2 module is compiled in:
nginx -v
nginx -V 2>&1 | tr ' ' '\n' | grep http_v2
The second command must print --with-http_v2_module. The module is not part of a default source build, but the distribution packages include it.
Step 2: Get a TLS certificate
If the site already runs on HTTPS, skip this step. Otherwise the quickest route is a free Let's Encrypt certificate with Certbot. Create a basic server block for your domain on port 80 first, then install Certbot the way its developers recommend and let it configure Nginx:
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/local/bin/certbot
sudo certbot --nginx -d example.com -d www.example.com
Certbot adds the listen 443 ssl and ssl_certificate lines to your server block. A self-signed certificate also works for testing HTTP/2, but browsers will show a warning.
Step 3: Enable HTTP/2 in the server block
Open the configuration of your site:
sudo nano /etc/nginx/sites-available/example.com
On Ubuntu 26.04 and Debian 13, add http2 on; to the server block that listens on port 443:
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name example.com www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
root /var/www/example.com/html;
index index.html;
}
On Ubuntu 24.04 and Debian 12, the directive does not exist yet. Put the parameter on the listen lines instead and leave out http2 on;:
listen 443 ssl http2;
listen [::]:443 ssl http2;
The directive is allowed in the http and server contexts. Placing http2 on; once in the http block of /etc/nginx/nginx.conf turns it on for every site; placing it in a server block limits it to that site. That per-site control is the practical advantage over the old parameter, which belonged to the listening socket and therefore affected every site sharing the same address and port.
If you upgrade a server from 24.04 to 26.04, the old listen ... http2 form keeps working but nginx -t prints a deprecation warning for each occurrence. Move to the directive when you see it.
Step 4: Test and reload
sudo nginx -t
sudo systemctl reload nginx
Only reload when the test reports that the syntax is ok and the test is successful. An "unknown directive http2" error means your Nginx is older than 1.25.1 and needs the listen form.
Step 5: Verify that HTTP/2 is in use
Ask curl which protocol version was negotiated:
curl -so /dev/null -w '%{http_version}\n' https://example.com/
The output 2 confirms HTTP/2; 1.1 means the server did not offer it. You can also look at the status line:
curl -sI https://example.com/ | head -n 1
It reads HTTP/2 200 for an HTTP/2 response. In a browser, open the developer tools, switch to the network tab and enable the "Protocol" column: requests to your site show h2.
To see the protocol per request on the server, the default access log format already records it: the request field ends in HTTP/2.0 for HTTP/2 clients.
Clean up obsolete HTTP/2 directives
Configurations copied from old tutorials often carry directives that current Nginx versions no longer use. According to the module documentation:
http2_push,http2_push_preloadandhttp2_max_concurrent_pushesare obsolete since 1.25.1. Server push was removed; browsers dropped support for it as well.http2_idle_timeout,http2_recv_timeout,http2_max_requests,http2_max_field_sizeandhttp2_max_header_sizeare obsolete since 1.19.7. Usekeepalive_timeout,client_header_timeout,keepalive_requestsandlarge_client_header_buffersinstead.
Remove these lines when nginx -t warns about them. The full list is in the ngx_http_v2_module documentation.
What about HTTP/3?
Nginx has had HTTP/3 (QUIC) support since version 1.25.0, but the ngx_http_v3_module documentation still describes it as experimental, and the module is not built by default: it needs the --with-http_v3_module build option. Check whether your package has it:
nginx -V 2>&1 | tr ' ' '\n' | grep http_v3
If the command prints the option, HTTP/3 is added next to HTTP/2, not instead of it. It runs over UDP, so it needs its own listen line with the quic parameter and a response header that tells browsers it is available:
listen 443 quic reuseport;
listen 443 ssl;
http2 on;
add_header Alt-Svc 'h3=":443"; ma=86400';
Use reuseport on only one listen line per address and port, and allow UDP port 443 in your firewall. Browsers make their first connection over HTTP/2 and switch to HTTP/3 after they have seen the Alt-Svc header, so HTTP/2 remains the baseline you want working first.
Frequently asked questions
Can I use HTTP/2 without a certificate?
Nginx can accept HTTP/2 on a port without TLS, but no mainstream browser will use it; they negotiate HTTP/2 only during the TLS handshake (ALPN). For a public website, HTTPS is a requirement in practice.
curl still reports HTTP/1.1. What is wrong?
The usual causes: the directive was added to the port 80 server block instead of the 443 one, Nginx was not reloaded, or a proxy, load balancer or CDN in front of the server terminates TLS and decides the protocol itself. Test directly against the server's IP address with curl --resolve example.com:443:203.0.113.10 to rule out the last one.
Does HTTP/2 change how Nginx talks to PHP-FPM or a proxied application?
No. The http2 directive only affects connections between clients and Nginx. Requests passed on with fastcgi_pass or proxy_pass use the protocol configured for that backend connection, independent of what the browser used.
Should I still combine CSS and JavaScript files or use several asset domains?
Spreading assets over several hostnames works against HTTP/2, because each hostname needs its own connection and multiplexing happens within one connection. Bundling is no longer needed to save connections, although very large numbers of tiny files still compress and cache less efficiently than a few sensible bundles.