ServerHandbook live check: run log ------------------------------------------------------------------------------ Article https://serverhandbook.com/kb/nginx-http2-ubuntu-24-04 Check scripts/live/checks/nginx-http2-ubuntu-24-04.mjs (sha256 25fcc2110749cd4036f59042248e8ef933a44d402fc4c0b0f537b3ac92b4893b) Ran at 2026-11-13T19:08:55Z (347 s) Result PASS, all 25 claims held Tested on System Ubuntu 24.04.4 LTS Kernel 6.8.0-138-generic Package nginx 1.24.0-2ubuntu7.19 Package openssl 3.0.13-0ubuntu3.15 Package certbot 2.9.0-1 Package python3-certbot-nginx 2.9.0-1 Package curl 8.5.0-2ubuntu10.13 Setup A fresh Ubuntu 24.04 cloud server from a hosting provider (its stock image, a public IPv4 address), with a domain and its www name pointed at it, ufw on, Nginx serving one site with a Let’s Encrypt certificate for both names and the www and HTTPS redirects, as the earlier articles leave it; reached over SSH as a sudo user. HTTP/2 was also checked from another network. Every version above was read from the server at run time. Passwords used on the throwaway test server are shown as [password]. How we test: https://serverhandbook.com/how-we-test ------------------------------------------------------------------------------ Claims (25), each with what the run saw ------------------------------------------------------------------------------ 1. ok a bare Ubuntu 24.04 server box (web-server) starts 2. ok (setup) certbot got a certificate for example.com and www.example.com | Saving debug log to /var/log/letsencrypt/letsencrypt.log | Account registered. | Requesting a certificate for example.com and www.example.com | | Successfully received certificate. | Certificate is saved at: /etc/letsencrypt/live/example.com/fullchain.pem | Key is saved at: /etc/letsencrypt/live/example.com/privkey.pem | This certificate expires on 2027-02-11. | These files will be updated when the certificate renews. | Certbot has set up a scheduled task to automatically renew this certificate in the background. | | Deploying certificate | Successfully deployed certificate for example.com to /etc/nginx/sites-enabled/example.com | Successfully deployed certificate for www.example.com to /etc/nginx/sites-enabled/example.com | Congratulations! You have successfully enabled HTTPS on https://example.com and https://www.example.com | | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | If you like Certbot, please consider supporting our work by: | * Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate | * Donating to EFF: https://eff.org/donate-le | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 3. ok before: curl talks HTTP/1.1 to https://example.com (curl offers h2; the server does not) | 1.1 4. ok Ubuntu’s nginx is built with http_v2_module and without http_v3_module | http_v2_module 5. ok nginx -v: nginx/1.24.0 (Ubuntu) | nginx version: nginx/1.24.0 (Ubuntu) 6. ok the file has four `listen … 443 ssl;` lines (two HTTPS blocks, IPv4 + IPv6) | 3: listen 80; | 4: listen [::]:80; | 11: listen 443 ssl; | 12: listen [::]:443 ssl; | 23: listen 443 ssl; | 24: listen [::]:443 ssl; 7. ok after sed: all four 443 lines read `443 ssl http2;`, the port-80 lines are unchanged | 3: 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; 8. ok nginx -t is successful | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | nginx: configuration file /etc/nginx/nginx.conf test is successful 9. ok after: curl talks HTTP/2 to https://example.com | 2 10. ok the status line is `HTTP/2 200` | HTTP/2 200 11. ok the www redirect also answers over HTTP/2: `HTTP/2 301` | HTTP/2 301 12. ok openssl: the TLS handshake picks `ALPN protocol: h2` | ALPN protocol: h2 13. ok (from another network) curl gets HTTP/2 200 | 2 200 14. ok plain http stays HTTP/1.1 (the redirect): `HTTP/1.1 301 Moved Permanently` | HTTP/1.1 301 Moved Permanently 15. ok `http2 on;` on nginx 1.24: [emerg] unknown directive "http2", test failed | 2026/11/13 19:12:39 [emerg] 3972#3972: unknown directive "http2" in /etc/nginx/conf.d/http2.conf:1 | nginx: configuration file /etc/nginx/nginx.conf test failed 16. ok (the file removed, nginx -t is successful again) | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | nginx: configuration file /etc/nginx/nginx.conf test is successful 17. ok http2 in the main block only: nginx -t is successful | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | nginx: configuration file /etc/nginx/nginx.conf test is successful 18. ok …and the www block, with no http2 on its lines, still answers HTTP/2 (same address and port) | HTTP/2 301 19. ok certbot renew --dry-run succeeds | Saving 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) | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 20. ok …and the four `ssl http2` lines are still there | 4 21. ok …and the site still answers HTTP/2 | 2 22. ok (tested on) the box reports its OS, kernel and the version of 5 package(s) | PRETTY_NAME="Ubuntu 24.04.4 LTS" | VIRT=none | KERNEL=6.8.0-138-generic | PKG certbot 2.9.0-1 | PKG curl 8.5.0-2ubuntu10.13 | PKG nginx 1.24.0-2ubuntu7.19 | PKG openssl 3.0.13-0ubuntu3.15 | PKG python3-certbot-nginx 2.9.0-1 23. ok undo: nginx -t successful | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | nginx: configuration file /etc/nginx/nginx.conf test is successful 24. ok undo: back to HTTP/1.1 | 1.1 25. ok (cleanup) the certificate the run got is revoked | Saving debug log to /var/log/letsencrypt/letsencrypt.log | Deleted all files relating to certificate example.com. | Congratulations! You have successfully revoked the certificate that was located at /etc/letsencrypt/live/example.com/cert.pem. ------------------------------------------------------------------------------ Commands and what they printed (25) ------------------------------------------------------------------------------ $ curl -sI https://example.com -o /dev/null -w '%{http_version}\n' 1.1 $ nginx -V 2>&1 | grep -oE 'http_v[23]_module' http_v2_module $ nginx -v nginx version: nginx/1.24.0 (Ubuntu) $ grep -n 'listen' /etc/nginx/sites-available/example.com 3: listen 80; 4: listen [::]:80; 11: listen 443 ssl; 12: listen [::]:443 ssl; 23: listen 443 ssl; 24: listen [::]:443 ssl; $ sudo cp /etc/nginx/sites-available/example.com ~/example.com.before-http2 $ sudo sed -i 's/listen \(.*\)443 ssl;/listen \1443 ssl http2;/' /etc/nginx/sites-available/example.com $ grep -n 'listen' /etc/nginx/sites-available/example.com 3: 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; $ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful $ sudo systemctl reload nginx $ curl -sI https://example.com -o /dev/null -w '%{http_version}\n' 2 $ curl -sI https://example.com | head -n 1 HTTP/2 200 $ curl -sI https://www.example.com | head -n 1 HTTP/2 301 $ echo | openssl s_client -connect example.com:443 -servername example.com -alpn h2 2>/dev/null | grep -a ALPN ALPN protocol: h2 $ curl -sI http://example.com | head -n 1 HTTP/1.1 301 Moved Permanently $ echo 'http2 on;' | sudo tee /etc/nginx/conf.d/http2.conf http2 on; $ sudo nginx -t 2026/11/13 19:12:39 [emerg] 3972#3972: unknown directive "http2" in /etc/nginx/conf.d/http2.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed $ sudo rm /etc/nginx/conf.d/http2.conf $ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful $ curl -sI https://www.example.com | head -n 1 HTTP/2 301 $ sudo certbot renew --dry-run Saving 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) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $ grep -c 'ssl http2' /etc/nginx/sites-available/example.com 4 $ curl -sI https://example.com -o /dev/null -w '%{http_version}\n' 2 $ sudo sed -i 's/ ssl http2;/ ssl;/' /etc/nginx/sites-available/example.com $ sudo nginx -t && sudo systemctl reload nginx nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful $ curl -sI https://example.com -o /dev/null -w '%{http_version}\n' 1.1 ------------------------------------------------------------------------------ The check's source (scripts/live/checks/nginx-http2-ubuntu-24-04.mjs) As it ran. ------------------------------------------------------------------------------ /** * KB: enable HTTP/2 in Nginx on Ubuntu 24.04. See which protocol the site speaks now (HTTP/1.1 over HTTPS) and that * Ubuntu's nginx 1.24 has the HTTP/2 module but no HTTP/3; add `http2` to every `listen … 443 ssl` line; nginx -t and * reload; check it with curl (the site and the www redirect), with openssl (ALPN: h2), and from another network; * plain http stays HTTP/1.1; `http2 on;` (the nginx 1.25.1+ form) is an "unknown directive" here; HTTP/2 is per * address and port, so one block with it turns it on for every site on 443; renewal leaves the lines alone; undo. * * Runs ONLY on a real rented server (LIVE_VPS=root@
LIVE_VPS_DOMAIN=, box.mjs `vps`): browsers use * HTTP/2 only over HTTPS with a certificate they trust, from a public certificate authority that reaches port 80. * Commands use example.com; box.mjs swaps the real name in on the way out and back on the way in. * * Hidden setup, as the earlier articles leave the server: the sudo user `deploy`, ufw on with SSH and 'Nginx Full', * Nginx with a site for example.com and www.example.com, a certificate for both names from certbot, and the three * server blocks of the redirect article (port 80 → https://example.com, https://www → https://example.com, the site). * * LIVE_LE_STAGING=1 sends certbot to Let's Encrypt's STAGING server while the check is written (never saved). At the * end (hidden) the certificate is revoked, so none stays valid for a name we do not use. */ import { spawnSync } from 'node:child_process' import { VPS, VPS_DOMAIN } from '../box.mjs' import { bareBox, reportBox } from '../lib.mjs' const STAGING = process.env.LIVE_LE_STAGING === '1' export const meta = { saveRun: !STAGING } const le = (cmd) => (STAGING ? cmd.replace(/^sudo certbot (\S+)/, 'sudo certbot $1 --test-cert') : cmd) const K = STAGING ? ' -k' : '' /** From another network (this machine), over the internet: the HTTP version curl used, and the status. */ const fromOutside = (url) => ( spawnSync( 'curl', ['-s', ...(STAGING ? ['-k'] : []), '-o', '/dev/null', '-m', '10', '-w', '%{http_version} %{http_code}', url.split('example.com').join(VPS_DOMAIN)], { encoding: 'utf8' }, ).stdout ?? '' ).trim() const FILE = '/etc/nginx/sites-available/example.com' const SSL = ` ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; include /etc/letsencrypt/options-ssl-nginx.conf; ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;` /** The redirect article's three blocks. `h2www` / `h2main`: whether each HTTPS block's listen lines carry http2. */ const blocks = (h2www, h2main) => `# 1. HTTP, both names: go to https://example.com server { listen 80; listen [::]:80; server_name example.com www.example.com; return 301 https://example.com$request_uri; } # 2. HTTPS, www: go to https://example.com server { listen 443 ssl${h2www ? ' http2' : ''}; listen [::]:443 ssl${h2www ? ' http2' : ''}; server_name www.example.com; ${SSL} return 301 https://example.com$request_uri; } # 3. HTTPS, example.com: the site server { listen 443 ssl${h2main ? ' http2' : ''}; listen [::]:443 ssl${h2main ? ' http2' : ''}; server_name example.com; ${SSL} root /var/www/example.com; index index.html; }` const write = (body) => `sudo tee ${FILE} > /dev/null <<'EOF'\n${body}\nEOF` const check = (ctx) => { if (!VPS) { ctx.check('this check runs on a real rented server (LIVE_VPS and LIVE_VPS_DOMAIN set)', false, 'LIVE_VPS is not set') return } return bareBox(ctx, async ({ sudoUser }) => { const { run, L } = sudoUser() const rc = (cmd, opts = {}) => run(cmd.replace(/curl /g, `curl${K} `), { show: cmd, ...opts }) L('sudo true') // ── hidden: as the UFW, Nginx, Let's Encrypt and redirect articles leave the server ────────── L('sudo ufw allow OpenSSH && sudo ufw --force enable') L('sudo apt-get update -qq && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq nginx certbot python3-certbot-nginx', 900000) L("sudo ufw allow 'Nginx Full'") L("sudo mkdir -p /var/www/example.com && echo '

example.com works

' | sudo tee /var/www/example.com/index.html") L(`${write('server {\n listen 80;\n listen [::]:80;\n server_name example.com www.example.com;\n root /var/www/example.com;\n index index.html;\n}')}\nsudo ln -s ${FILE} /etc/nginx/sites-enabled/ && sudo systemctl reload nginx`) const got = L(le('sudo certbot --nginx -d example.com -d www.example.com --non-interactive --agree-tos -m admin@example.com --no-eff-email'), 300000) ctx.check('(setup) certbot got a certificate for example.com and www.example.com', /Successfully deployed certificate for www\.example\.com/.test(got), got) L(`${write(blocks(false, false))}\nsudo nginx -t && sudo systemctl reload nginx`) // ── step 1: what the site speaks now ───────────────────────────────────────────────────── const v1 = rc(`curl -sI https://example.com -o /dev/null -w '%{http_version}\\n'`, { id: 'version-before' }) ctx.check('before: curl talks HTTP/1.1 to https://example.com (curl offers h2; the server does not)', v1.out.trim() === '1.1', v1.out) const mods = run(`nginx -V 2>&1 | grep -oE 'http_v[23]_module'`, { id: 'modules' }) ctx.check('Ubuntu’s nginx is built with http_v2_module and without http_v3_module', mods.out.trim() === 'http_v2_module', mods.out) const ver = run('nginx -v', { id: 'nginx-version' }) ctx.check('nginx -v: nginx/1.24.0 (Ubuntu)', /nginx\/1\.24\.0 \(Ubuntu\)/.test(ver.out), ver.out) // ── step 2: add http2 to the listen lines ──────────────────────────────────────────────── const g1 = run(`grep -n 'listen' ${FILE}`, { id: 'listen-before' }) ctx.check('the file has four `listen … 443 ssl;` lines (two HTTPS blocks, IPv4 + IPv6)', (g1.out.match(/443 ssl;/g) ?? []).length === 4, g1.out) run(`sudo cp ${FILE} ~/example.com.before-http2`, { id: 'backup' }) run(`sudo sed -i 's/listen \\(.*\\)443 ssl;/listen \\1443 ssl http2;/' ${FILE}`, { id: 'sed-http2' }) const g2 = run(`grep -n 'listen' ${FILE}`, { id: 'listen-after' }) ctx.check('after sed: all four 443 lines read `443 ssl http2;`, the port-80 lines are unchanged', (g2.out.match(/443 ssl http2;/g) ?? []).length === 4 && (g2.out.match(/listen (\[::\]:)?80;/g) ?? []).length === 2, g2.out) const t1 = run('sudo nginx -t', { id: 'test' }) ctx.check('nginx -t is successful', t1.exit === 0 && /test is successful/.test(t1.out), t1.out) run('sudo systemctl reload nginx', { id: 'reload' }) // ── step 3: check it ───────────────────────────────────────────────────────────────────── const v2 = rc(`curl -sI https://example.com -o /dev/null -w '%{http_version}\\n'`, { id: 'version-after' }) ctx.check('after: curl talks HTTP/2 to https://example.com', v2.out.trim() === '2', v2.out) const h = rc(`curl -sI https://example.com | head -n 1`, { id: 'status-line' }) ctx.check('the status line is `HTTP/2 200`', /^HTTP\/2 200/.test(h.out.trim()), h.out) const w = rc(`curl -sI https://www.example.com | head -n 1`, { id: 'status-www' }) ctx.check('the www redirect also answers over HTTP/2: `HTTP/2 301`', /^HTTP\/2 301/.test(w.out.trim()), w.out) const alpn = run(`echo | openssl s_client -connect example.com:443 -servername example.com -alpn h2 2>/dev/null | grep -a ALPN`, { id: 'alpn' }) ctx.check('openssl: the TLS handshake picks `ALPN protocol: h2`', /ALPN protocol: h2/.test(alpn.out), alpn.out) const out1 = fromOutside('https://example.com/') ctx.check('(from another network) curl gets HTTP/2 200', out1 === '2 200', out1) const p80 = rc(`curl -sI http://example.com | head -n 1`, { id: 'http-plain' }) ctx.check('plain http stays HTTP/1.1 (the redirect): `HTTP/1.1 301 Moved Permanently`', /^HTTP\/1\.1 301 Moved Permanently/.test(p80.out.trim()), p80.out) // ── `http2 on;` is for nginx 1.25.1 and later ──────────────────────────────────────────── run(`echo 'http2 on;' | sudo tee /etc/nginx/conf.d/http2.conf`, { id: 'http2-on-write' }) const t2 = run('sudo nginx -t', { id: 'http2-on-test' }) ctx.check('`http2 on;` on nginx 1.24: [emerg] unknown directive "http2", test failed', t2.exit !== 0 && /unknown directive "http2" in \/etc\/nginx\/conf\.d\/http2\.conf:1/.test(t2.out) && /test failed/.test(t2.out), t2.out) run('sudo rm /etc/nginx/conf.d/http2.conf', { id: 'http2-on-rm' }) const t3 = L('sudo nginx -t 2>&1') ctx.check('(the file removed, nginx -t is successful again)', /test is successful/.test(t3), t3) // ── per address and port: one block with http2 turns it on for all on 443 ──────────────── L(`${write(blocks(false, true))}`) const t4 = run('sudo nginx -t', { id: 'one-block-test' }) ctx.check('http2 in the main block only: nginx -t is successful', t4.exit === 0 && /test is successful/.test(t4.out), t4.out) L('sudo systemctl reload nginx') const w2 = rc(`curl -sI https://www.example.com | head -n 1`, { id: 'one-block-www' }) ctx.check('…and the www block, with no http2 on its lines, still answers HTTP/2 (same address and port)', /^HTTP\/2 301/.test(w2.out.trim()), w2.out) L(`${write(blocks(true, true))}\nsudo nginx -t && sudo systemctl reload nginx`) // ── renewal keeps the lines ────────────────────────────────────────────────────────────── const dry = run(le('sudo certbot renew --dry-run'), { show: 'sudo certbot renew --dry-run', id: 'dry-run', timeout: 300000 }) ctx.check('certbot renew --dry-run succeeds', dry.exit === 0 && /Congratulations, all simulated renewals succeeded/.test(dry.out), dry.out) const cnt = run(`grep -c 'ssl http2' ${FILE}`, { id: 'count-after-renew' }) ctx.check('…and the four `ssl http2` lines are still there', cnt.out.trim() === '4', cnt.out) const v3 = rc(`curl -sI https://example.com -o /dev/null -w '%{http_version}\\n'`, { id: 'version-after-renew' }) ctx.check('…and the site still answers HTTP/2', v3.out.trim() === '2', v3.out) reportBox( ctx, L, 'A fresh Ubuntu 24.04 cloud server from a hosting provider (its stock image, a public IPv4 address), with a domain and its www name pointed at it, ufw on, Nginx serving one site with a Let’s Encrypt certificate for both names and the www and HTTPS redirects, as the earlier articles leave it; reached over SSH as a sudo user. HTTP/2 was also checked from another network.', ['nginx', 'openssl', 'certbot', 'python3-certbot-nginx', 'curl'], ) // ── undo ───────────────────────────────────────────────────────────────────────────────── run(`sudo sed -i 's/ ssl http2;/ ssl;/' ${FILE}`, { id: 'undo-sed' }) const tu = run('sudo nginx -t && sudo systemctl reload nginx', { id: 'undo-reload' }) ctx.check('undo: nginx -t successful', tu.exit === 0, tu.out) const vu = rc(`curl -sI https://example.com -o /dev/null -w '%{http_version}\\n'`, { id: 'version-undo' }) ctx.check('undo: back to HTTP/1.1', vu.out.trim() === '1.1', vu.out) // ── hidden: revoke the certificate the run got ─────────────────────────────────────────── const rv = L(le('sudo certbot revoke --cert-name example.com --non-interactive --delete-after-revoke'), 300000) ctx.check('(cleanup) the certificate the run got is revoked', /revoked/i.test(rv), rv) }) } export default check