Short answer

On Ubuntu 26.04 (Nginx 1.28) put http2 on; in a file under /etc/nginx/conf.d/, run sudo nginx -t and sudo systemctl reload nginx. On 24.04 (Nginx 1.24) add http2 to every listen … 443 ssl line instead. Check with curl -sI https://example.com: the first line says HTTP/2 200.

Tested on Ubuntu 26.04 and 24.04, two separate runs. On 24.04? 7 sections differ, each step marked “On Ubuntu 24.04” right under it: Step 1: See what your site speaks now, Step 2: Turn on HTTP/2, “the "listen … http2" directive is deprecated”: listen http2 or http2 on?, Do I need it in every server block?, Does certbot renewal remove it?, What about HTTP/3?, Undo. Everything that differed

Before you start

  • An Ubuntu 26.04 or 24.04 server with Nginx and a site on HTTPS, with a certificate from certbot (Let’s Encrypt for Nginx). Browsers use HTTP/2 only over HTTPS, so a site on plain http gains nothing from this page.
  • Put your domain in place of example.com everywhere below. The test server had the three blocks from redirect www and HTTP to HTTPS: one on port 80 and two on 443.

Step 1: See what your site speaks now

curl offers HTTP/2 on every https request, and %{http_version} prints what the server agreed to:

Server
$ curl -sI https://example.com -o /dev/null -w '%{http_version}\n'1.1
Output hidden (1 line)

1.1 means HTTP/1.1. Nginx does not turn HTTP/2 on by itself, and certbot does not add it either. Ubuntu’s Nginx has the HTTP/2 module built in, so there is nothing to install. On 26.04 it has an HTTP/3 module too:

Server
$ nginx -V 2>&1 | grep -oE 'http_v[23]_module'http_v2_modulehttp_v3_module
Output hidden (2 lines)
Server
$ nginx -vnginx version: nginx/1.28.3 (Ubuntu)
Output hidden (1 line)
On Ubuntu 24.04

On 24.04 the first command prints only http_v2_module: Ubuntu’s Nginx 1.24 has no HTTP/3 module. nginx -v prints nginx/1.24.0.

Step 2: Turn on HTTP/2

Nginx 1.25.1 added a directive of its own, http2 on;, and Ubuntu 26.04 ships 1.28. A file under conf.d is read inside the http block, so one line there covers every HTTPS site on the server:

Server
$ echo 'http2 on;' | sudo tee /etc/nginx/conf.d/http2.confhttp2 on;
Output hidden (1 line)
Server
$ sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
Output hidden (2 lines)
Server
$ sudo systemctl reload nginx
On Ubuntu 24.04

Nginx 1.24 has no http2 directive (step 1 showed its version), so on 24.04 the setting is a word on the listen lines. Find the lines that listen on 443:

Server
$ grep -n 'listen' /etc/nginx/sites-available/example.com3:    listen 80;4:    listen [::]:80;11:    listen 443 ssl;12:    listen [::]:443 ssl;23:    listen 443 ssl;24:    listen [::]:443 ssl;
Output hidden (6 lines)

There are four: IPv4 and IPv6 for each of the two HTTPS blocks. A file that certbot wrote has listen 443 ssl; # managed by Certbot, and the command below works on those lines too. Keep a copy first, so you can go back, then add http2 after ssl on every listen … 443 ssl; line (port 80 is left alone):

Server
$ sudo cp /etc/nginx/sites-available/example.com ~/example.com.before-http2
Server
$ sudo sed -i 's/listen \(.*\)443 ssl;/listen \1443 ssl http2;/' /etc/nginx/sites-available/example.com
Server
$ grep -n 'listen' /etc/nginx/sites-available/example.com3:    listen 80;4:    listen [::]:80;11:    listen 443 ssl http2;12:    listen [::]:443 ssl http2;23:    listen 443 ssl http2;24:    listen [::]:443 ssl http2;
Output hidden (6 lines)
Server
$ sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
Output hidden (2 lines)
Server
$ sudo systemctl reload nginx

Step 3: Check that HTTP/2 works

Server
$ curl -sI https://example.com -o /dev/null -w '%{http_version}\n'2
Output hidden (1 line)

The status line shows it too. HTTP/2 writes it without a reason phrase, so it is HTTP/2 200, not HTTP/1.1 200 OK:

Server
$ curl -sI https://example.com | head -n 1HTTP/2 200
Output hidden (1 line)
Server
$ curl -sI https://www.example.com | head -n 1HTTP/2 301
Output hidden (1 line)

Browsers and curl agree on HTTP/2 inside the TLS handshake, before any page is asked for. This is called ALPN. openssl shows what the server picked. The -a makes grep read the output as text: with a real certificate openssl prints some raw bytes, and plain grep then only says binary file matches:

Server
$ echo | openssl s_client -connect example.com:443 -servername example.com -alpn h2 2>/dev/null | grep -a ALPNALPN protocol: h2
Output hidden (1 line)

In the test the same check from another network also got HTTP/2 200. In a browser, open the developer tools, go to the Network tab and reload. The Protocol column, which you may need to switch on with a right-click on the column headers, shows h2.

Does HTTP/2 work without HTTPS?

Not in browsers. They use HTTP/2 only over TLS, and plain http stays HTTP/1.1. That is fine when port 80 only redirects to https:

Server
$ curl -sI http://example.com | head -n 1HTTP/1.1 301 Moved Permanently
Output hidden (1 line)

“the "listen … http2" directive is deprecated”: listen http2 or http2 on?

Most guides still write listen 443 ssl http2;. On 26.04 it works, and nginx -t warns once for each such line. To see it, the test copied the site’s file, added http2 to its four listen lines, and ran the test:

Server
$ sudo cp /etc/nginx/sites-available/example.com ~/example.com.before-http2
Server
$ sudo sed -i 's/listen \(.*\)443 ssl;/listen \1443 ssl http2;/' /etc/nginx/sites-available/example.com
Server
$ sudo nginx -t2026/11/18 23:18:27 [warn] 4713#4713: the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/example.com:112026/11/18 23:18:27 [warn] 4713#4713: the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/example.com:122026/11/18 23:18:27 [warn] 4713#4713: the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/example.com:232026/11/18 23:18:27 [warn] 4713#4713: the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/sites-enabled/example.com:24nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
Output hidden (6 lines)

The warning is Nginx’s own, from the line of source linked below. The site would still answer, but each reload prints it, so keep the new form and put the old file back:

Server
$ sudo cp ~/example.com.before-http2 /etc/nginx/sites-available/example.com
On Ubuntu 24.04

On 24.04 it is the other way round: listen … http2 is the right form and prints no warning. The new directive is unknown to Nginx 1.24, which the test showed by putting it in its own file:

Server
$ echo 'http2 on;' | sudo tee /etc/nginx/conf.d/http2.confhttp2 on;
Output hidden (1 line)
Server
$ sudo nginx -t2026/11/18 23:25:55 [emerg] 4432#4432: unknown directive "http2" in /etc/nginx/conf.d/http2.conf:1nginx: configuration file /etc/nginx/nginx.conf test failed
Output hidden (2 lines)

Remove the file again and keep the listen lines from step 2. If you later move to a newer Nginx, change the lines then.

Server
$ sudo rm /etc/nginx/conf.d/http2.conf

Do I need it in every server block?

On 26.04, no: the file from step 2 sits outside any server block, so it covers all of them. The test shows it: the main name answered HTTP/2 200 and the www redirect HTTP/2 301, and neither block’s listen lines mention http2. The directive is also allowed inside one server block, as the source line below shows; this run did not try that.

On Ubuntu 24.04

On 24.04 write http2 in every block anyway. Nginx 1.24 keeps HTTP/2 per address and port, not per site. In the test, http2 was taken off the www block’s two lines and left on the main block. The test still passed:

Server
$ sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
Output hidden (2 lines)

After a reload, the www block answered over HTTP/2 even though its own lines did not ask for it:

Server
$ curl -sI https://www.example.com | head -n 1HTTP/2 301
Output hidden (1 line)

So one site with http2 turns it on for every HTTPS site on that address, and taking it off one site does not turn it off. Write it on every 443 line, so the files say what the server does.

Does certbot renewal remove it?

No. Renewal gets a new certificate and reloads Nginx; it does not rewrite your Nginx files. A dry run, then a look at the file and the protocol again:

Server
$ sudo certbot renew --dry-runSaving debug log to /var/log/letsencrypt/letsencrypt.log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Processing /etc/letsencrypt/renewal/example.com.conf- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Account registered.Simulating renewal of an existing certificate for example.com and www.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Congratulations, all simulated renewals succeeded:  /etc/letsencrypt/live/example.com/fullchain.pem (success)- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Output hidden (12 lines)
Server
$ cat /etc/nginx/conf.d/http2.confhttp2 on;
Output hidden (1 line)
Server
$ curl -sI https://example.com -o /dev/null -w '%{http_version}\n'2
Output hidden (1 line)
On Ubuntu 24.04

On 24.04 the setting lives in the site’s own file, so the check is a count of its http2 lines:

Server
$ grep -c 'ssl http2' /etc/nginx/sites-available/example.com4
Output hidden (1 line)

When you add a new site with certbot --nginx, certbot writes listen 443 ssl; without http2. That site still gets HTTP/2 from the others on the same port, but add http2 to its lines too.

What about HTTP/3?

Step 1 showed that Ubuntu 26.04’s Nginx is built with http_v3_module, so HTTP/3 is possible with Ubuntu’s own package. It also needs UDP port 443 open and its own listen lines, which this page does not cover or test. Turning on HTTP/2 does not turn it on.

On Ubuntu 24.04

On 24.04 step 1 showed no http_v3_module, so HTTP/3 is not available from Ubuntu’s package. It needs an Nginx built with that module, which is a different install and not covered here.

Undo

Remove the file, then test and reload:

Server
$ sudo rm /etc/nginx/conf.d/http2.conf
Server
$ sudo nginx -t && sudo systemctl reload nginxnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
Output hidden (2 lines)
Server
$ curl -sI https://example.com -o /dev/null -w '%{http_version}\n'1.1
Output hidden (1 line)

Back to 1.1.

On Ubuntu 24.04

On 24.04 take http2 off the lines, or put back the copy from step 2 with sudo cp ~/example.com.before-http2 /etc/nginx/sites-available/example.com. Another site on the same port with http2 would keep it on for all of them.

Server
$ sudo sed -i 's/ ssl http2;/ ssl;/' /etc/nginx/sites-available/example.com

What these steps changed on the server

Both runs recorded the server before the first step and after the last (see the Tested on box below). No package was installed, no service was enabled and no port opened or closed. On 26.04 one file was added in /etc, /etc/nginx/conf.d/http2.conf; on 24.04 one was changed, the site’s own file (/etc/nginx/sites-available/example.com). The test-server account from the renewal dry run adds three small files under /etc/letsencrypt on both. The disk holds about 0.2 MB more.

testssl.sh 3.2.5, run against the site with HTTP/2 on, gave grade A+ on both releases and offers TLS 1.2 and 1.3 only. Its notes are the same as on the Let’s Encrypt page: no HSTS header, no DNS CAA record, no security headers, and BREACH because the test page is gzip-compressed. HTTP/2 itself changes none of them.

Ubuntu 26.04 vs 24.04: what changed

The result is the same, HTTP/2 200. The way to get it is not:

WhatUbuntu 26.04Ubuntu 24.04
SystemUbuntu 26.04.1 LTS7.0.0-30-genericUbuntu 24.04.4 LTS6.8.0-138-generic
nginx1.28.3-2ubuntu1.121.24.0-2ubuntu7.19
openssl3.5.5-1ubuntu3.43.0.13-0ubuntu3.15
certbot4.0.0-42.9.0-1
python3-certbot-nginx4.0.0-32.9.0-1
curl8.18.0-1ubuntu2.48.5.0-2ubuntu10.13
Nginx version1.28.31.24.0
How HTTP/2 is turned onhttp2 on; (one line, in conf.d)http2 on each listen … 443 ssl line
listen … 443 ssl http2;works, but nginx -t warns: the “listen … http2” directive is deprecatedthe right form, no warning
http2 on;worksfails: unknown directive
HTTP/3 module in Ubuntu’s buildhttp_v3_module is built innot built
Per site or per addressone line covers every sitekept per address and port: one site with http2 turns it on for all
Ports opened, testssl.sh gradenone; A+none; A+
ProofRun log, 23 checks passedRun log, 26 checks passed