Web servers and networking · Intermediate · 13 min
Turn on HTTP/2 and HTTP/3 in Nginx
By Padding · Updated 18 Nov 2026
Ubuntu 26.04.1 LTS · Nginx 1.30.8 stable (nginx.org repo) · curl 8.18.0
You will have your HTTPS site on Nginx 1.30 answering over HTTP/2 and HTTP/3, with UDP port 443 open, 0-RTT left off on purpose, and a log that shows which protocol each visitor used.
On this page
Most HTTPS sites on Nginx still answer every visitor over HTTP/1.1, because Nginx leaves HTTP/2 and HTTP/3 off until you ask for them. Turning them on takes a few lines, but each line has a detail that trips people up: the old way of enabling HTTP/2 now prints a warning, HTTP/3 runs over UDP so the firewall has to change too, reuseport may only appear once per port, and 0-RTT early data trades a round trip for a replay risk.
In this tutorial you will change one existing site, example.com, on port 443. Replace example.com with your own domain throughout. You will record what the site speaks now, turn on HTTP/2, add a QUIC listener for HTTP/3 and advertise it, open UDP 443, decide what to do about early data, and check the result from curl, a browser and the access log.
If you want to understand what the three versions change on the wire before you switch them on, work through /tutorials/compare-http-1-1-http-2-and-http-3 first. This tutorial is the production change.
Step 1 · Check that your Nginx build can do it
HTTP/2 and HTTP/3 are separate Nginx modules, compiled in or not. The nginx.org packages include both. Ubuntu's own nginx package is an older release, so if you installed from the Ubuntu archive, switch to nginx.org first as in /tutorials/install-nginx-on-ubuntu-26-04.
Ask Nginx what it was built with:
nginx -v
nginx -V 2>&1 | grep -o -E 'with-http_v[23]_module'
nginx -V 2>&1 | grep -o 'built with OpenSSL [^ ]*'The first line prints nginx version: nginx/1.30.x. The second command prints two lines, with-http_v2_module and with-http_v3_module. The third names the OpenSSL version Nginx was compiled against, something like built with OpenSSL 3.5.x.
QUIC, the transport under HTTP/3, always uses TLS 1.3. Nginx enables TLS 1.2 and 1.3 by default. Check that nothing in your configuration narrows that:
sudo nginx -T 2>/dev/null | grep -n 'ssl_protocols' || echo "ssl_protocols not set: TLSv1.2 and TLSv1.3 are on"If the command prints ssl_protocols lines, each must include TLSv1.3. Certbot's shared options file sets TLSv1.2 TLSv1.3, which is fine.
Check it worked
You saw both with-http_v2_module and with-http_v3_module, and every ssl_protocols line (if there are any) includes TLSv1.3.
Step 2 · Record what the site speaks today
Before you change anything, note the starting point. curl offers HTTP/2 by default over HTTPS, so the answer shows what the server accepts:
curl -sI https://example.com/ | head -n 1
curl -s -o /dev/null -w '%{http_version}\n' https://example.com/With HTTP/2 still off, the first line is HTTP/1.1 200 OK and the second prints 1.1. If you already see HTTP/2 200, HTTP/2 is on somewhere; the next step shows where to look.
Find the file that holds the HTTPS server block for your domain:
sudo grep -rln 'server_name.*example.com' /etc/nginx/conf.d/This tutorial assumes it is /etc/nginx/conf.d/example.com.conf. Use whichever path the command prints. Make a copy so you can go back:
sudo cp /etc/nginx/conf.d/example.com.conf /root/example.com.conf.before-h2-h3Check it worked
You have a note of 1.1 from curl, you know which file to edit, and sudo ls /root/ lists example.com.conf.before-h2-h3.
Step 3 · Turn on HTTP/2
Since Nginx 1.25.1, HTTP/2 has its own directive, http2 on;, set per server block. Older guides, and older Certbot runs, put http2 on the listen line instead (listen 443 ssl http2;). That still works, but Nginx now warns that the listen ... http2 form is deprecated each time you test or reload. If your file has it, delete the word http2 from the listen line and add the directive.
Open the file:
sudo nano /etc/nginx/conf.d/example.com.confAdd http2 on; under the listen 443 ssl; line. The HTTPS server block now looks like this. Your file probably has more lines, such as the ones Certbot added and marked # managed by Certbot; keep them and only add the new one.
server {
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;
root /var/www/example.com;
index index.html;
}Test, then reload:
sudo nginx -t && sudo systemctl reload nginxnginx -t ends with test is successful and prints no [warn] lines about http2.
Check it worked
curl -sI https://example.com/ | head -n 1
curl -s -o /dev/null -w '%{http_version}\n' https://example.com/The first line is now HTTP/2 200 and the second prints 2. Plain-HTTP visitors are unaffected: browsers only use HTTP/2 over TLS, so the port 80 block needs no change.
Step 4 · Add a QUIC listener and advertise HTTP/3
HTTP/3 runs over QUIC, and QUIC runs over UDP, so Nginx needs a second listener on the same port number, this time for UDP. Three lines do it:
listen 443 quic reuseport;opens UDP port 443 for QUIC.reuseportgives each worker process its own socket, which Nginx needs to route QUIC packets correctly when it runs more than one worker.http3 on;allows HTTP/3 on that listener. It is on by default, but writing it down makes the intent clear.add_header Alt-Svc 'h3=":443"; ma=86400' always;tells clients that HTTP/3 is on offer. A browser cannot know a server speaks QUIC until it is told, so its first visit always goes over TCP. The header says "HTTP/3 is available on UDP port 443 of this host, remember that for 86,400 seconds (one day)".alwayssends it on error responses too.
One rule catches people with several sites on one server: socket options such as reuseport may appear only once for each address and port, across all server blocks. Put listen 443 quic reuseport; in one server block, usually the main site, and write plain listen 443 quic; in every other block that should speak HTTP/3. Otherwise nginx -t fails with an error about duplicate listen options.
If your block also listens on IPv6 (listen [::]:443 ssl;), add listen [::]:443 quic reuseport; next to it in the same way.
Edit the file again. The HTTPS server block becomes:
server {
listen 443 ssl;
listen 443 quic reuseport;
http2 on;
http3 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;
add_header Alt-Svc 'h3=":443"; ma=86400' always;
root /var/www/example.com;
index index.html;
}A trap with add_header: a location block that has any add_header of its own does not inherit the ones from the server block. If you set, say, cache headers inside location /assets/, repeat the Alt-Svc line there too, or those responses will not advertise HTTP/3.
There is also quic_retry on;, which makes a new client prove its address with a token before Nginx does any work for it. It helps against floods of spoofed packets, at the cost of one extra round trip on new connections. Leave it off unless you see that kind of traffic.
sudo nginx -t && sudo systemctl reload nginxCheck it worked
Nginx now listens on both TCP and UDP port 443:
sudo ss -tlnp 'sport = :443'
sudo ss -ulnp 'sport = :443'The first command shows a LISTEN line with nginx in the process column. The second shows UNCONN lines (UDP has no listening state) with nginx, usually one per worker because of reuseport.
And the site advertises HTTP/3:
curl -sI https://example.com/ | grep -i '^alt-svc'It prints alt-svc: h3=":443"; ma=86400.
Step 5 · Open UDP port 443 in every firewall
This is the step most often missed. Your HTTPS rules almost certainly allow TCP 443 only. Until UDP 443 is open, browsers try QUIC, time out, and quietly fall back to HTTP/2, so the site still works and nothing tells you HTTP/3 is not being used.
On the server, add a UFW rule for UDP. This adds access and removes nothing, so it cannot lock you out:
sudo ufw allow 443/udp
sudo ufw statusThe status table now lists 443/udp with ALLOW next to your existing 443/tcp (or 443) rule. If UFW shows Status: inactive, it is not filtering anything and you can skip it.
Then open your cloud provider's firewall. Whether it is called a security group, a firewall rule or a network policy, add an inbound rule for protocol UDP, port 443, from anywhere, next to the existing TCP 443 rule. Do the same on any load balancer in front of the server: many only forward TCP, and a TCP-only load balancer means HTTP/3 cannot reach Nginx at all.
Some networks block UDP 443, including some office networks and mobile carriers. That is why HTTP/2 stays on: clients that cannot use QUIC keep working over TCP.
Check it worked
sudo ufw status lists 443/udp ALLOW, and your cloud console shows an inbound UDP 443 rule. The real proof comes from a client in the last step.
Step 6 · Decide what to do about 0-RTT early data
With TLS 1.3, and so with QUIC, a returning visitor can send its first request inside the handshake, before it completes. This is 0-RTT, and in Nginx it is ssl_early_data on;. It saves one round trip, which is noticeable on high-latency mobile links.
The cost is that early data can be replayed. An attacker who captures that first flight of packets can send it to the server again, and the server cannot tell the copy from the original, because the handshake that would prove freshness has not finished yet. For a GET of a page that is harmless. For a POST that places an order or sends money, it means the action can happen twice.
Leave early data off unless you have a reason and a plan. Nginx's default is off, so the safe setting is to not mention it at all. Check that nothing turned it on:
sudo nginx -T 2>/dev/null | grep -n 'ssl_early_data' || echo "ssl_early_data not set: 0-RTT is off"You want ssl_early_data not set: 0-RTT is off, or a line that ends in off;.
If you do turn it on later, two conditions apply. Nginx must be built with OpenSSL 3.5.1 or later for 0-RTT to work over QUIC (the build check in the first step shows yours). And every app behind Nginx must refuse unsafe requests that arrive as early data. Nginx sets $ssl_early_data to 1 for those requests; pass it on so the app can answer 425 Too Early, which tells the client to retry once the handshake is done:
location / {
proxy_set_header Early-Data $ssl_early_data;
proxy_pass http://127.0.0.1:3000;
}The app then returns 425 for any non-GET request that carries Early-Data: 1. If you cannot change every app, keep 0-RTT off.
Check it worked
The nginx -T check printed ssl_early_data not set: 0-RTT is off, or you have turned it on with the Early-Data header passed to an app that answers 425.
Step 7 · Confirm HTTP/3 from a client and in the log
Curl and the browser can each tell you which protocol they used, but the server's own log is the record that covers every visitor. Add a log format that writes the protocol. $server_protocol is HTTP/1.1, HTTP/2.0 or HTTP/3.0, and $http3 is h3 on HTTP/3 connections and empty otherwise.
Edit the site file once more. Put the log_format line at the top of the file, above the first server { (files in conf.d are read inside Nginx's http block, where log_format belongs), and add the access_log line inside the HTTPS server block:
log_format protocols '$remote_addr [$time_local] "$request" $status $server_protocol "$http3"';
server {
listen 443 ssl;
listen 443 quic reuseport;
http2 on;
http3 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;
add_header Alt-Svc 'h3=":443"; ma=86400' always;
access_log /var/log/nginx/example.com.protocols.log protocols;
root /var/www/example.com;
index index.html;
}sudo nginx -t && sudo systemctl reload nginxMake a request and read the log:
curl -s -o /dev/null https://example.com/
sudo tail -n 1 /var/log/nginx/example.com.protocols.logThe line ends in 200 HTTP/2.0 "": HTTP/2, not HTTP/3.
Now make an HTTP/3 request from your own computer. Ubuntu 26.04's curl is built without HTTP/3; run curl --version and look for HTTP3 on the Features line. On macOS or Linux, Homebrew's curl has it (brew install curl, then call it by the full path Homebrew prints, because the system curl comes first on your PATH):
curl --http3-only -sI https://example.com/ | head -n 1It prints HTTP/3 200. --http3-only fails instead of falling back to TCP, so a timeout here means UDP 443 is blocked somewhere between you and Nginx: check UFW, the cloud firewall and any load balancer. Then look at the server log again with sudo tail -n 1 /var/log/nginx/example.com.protocols.log; the newest line ends in HTTP/3.0 "h3".
In a browser, open your site, then open the developer tools on the Network panel. Right-click the column headings and turn on Protocol. The first load shows h2, because the browser has not seen Alt-Svc yet. Reload, or open the site in a new tab, and requests show h3. If they stay on h2, close the browser fully and try again, since browsers keep existing connections open for a while.
HTTP/3 helps most where connections are unreliable: mobile networks that drop packets, and phones that move between Wi-Fi and mobile data, which QUIC can survive without starting a new connection. If many of your visitors browse on low-end Android phones over prepaid mobile data, as is common in much of Africa, watch the share of HTTP/3.0 lines in this log over a week. It tells you how many of them get the benefit, and a share near zero points to UDP being blocked on your side.
Check it worked
curl from your computer printed HTTP/3 200, the browser's Protocol column shows h3 after a reload, and the protocol log has lines ending in HTTP/3.0 "h3".
To undo the change, copy /root/example.com.conf.before-h2-h3 back over the site file, then test and reload. Clients that remembered Alt-Svc try QUIC for up to a day, fail, and fall back to TCP without visitors noticing.
Next steps
- See multiplexing, header compression and HTTP/3 discovery up close in a lab:
/tutorials/compare-http-1-1-http-2-and-http-3. - Make each response smaller and cache it longer, which matters on every protocol version:
/tutorials/compress-and-cache-static-files-in-nginx. - Use curl's timers to find where a slow page spends its time:
/tutorials/debug-a-slow-or-failing-website-with-curl. - Renew and check the certificate HTTP/2 and HTTP/3 both depend on:
/tutorials/free-https-with-lets-encrypt-and-nginx.
Related tutorials
- Write Nginx location blocks that match what you expectYou will build a practice Nginx 1.30 server where every location block labels its responses, predict which block answers each of twelve URLs, check your answers with curl, and fix the alias, regex-order and proxy_pass mistakes that catch most people out.
- Write a server firewall with nftablesYou will write one /etc/nftables.conf with a default-drop input chain, rate-limited SSH, named address sets, counters and logging, and load it over SSH behind a timer that undoes it if you lose your connection.
- Watch a TCP connection open and close with tcpdumpYou will capture a curl request to a local web server with tcpdump on Ubuntu 26.04, read its handshake, data and teardown line by line, see the reset a closed port sends, and save, filter and rotate captures as pcap files.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials