Enable HTTP/3 and QUIC in Nginx for WordPress
HTTP/3 runs over QUIC, a transport on top of UDP. Compared with HTTP/2 over TCP it sets up a connection faster (the TLS handshake is part of the QUIC handshake), and a lost packet does not stall all the other requests on the connection (no TCP head-of-line blocking). The difference is biggest on mobile and lossy networks. Since version 1.25.0 Nginx supports HTTP/3 in its mainline builds, next to HTTP/2, and browsers that do not use it keep working over HTTP/2.
Problem: A WordPress server is on HTTP/2, and you want the lower latency of HTTP/3 for visitors on mobile networks without breaking anything for the others.
Solution: On Nginx 1.25+ built with the HTTP/3 module, add a quic listener on UDP 443 next to the existing TLS listener, enable http3, advertise it with the Alt-Svc header, open UDP 443 in the firewall, and check with a browser or curl --http3.
Check the Nginx build
nginx -V 2>&1 | grep -o 'with-http_v3_module'
If nothing is printed, install a build with the module (the packages from nginx.org mainline include it) before changing the configuration.
The server block
server {
listen 443 ssl;
listen [::]:443 ssl;
listen 443 quic reuseport;
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;
ssl_protocols TLSv1.2 TLSv1.3;
# Tell browsers that HTTP/3 is available on UDP 443
add_header Alt-Svc 'h3=":443"; ma=86400' always;
root /var/www/example.com;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
location ~* \.(js|css|png|jpg|webp|avif|woff2|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
add_header Alt-Svc 'h3=":443"; ma=86400' always;
}
}
Details that matter:
reuseportmay appear only once per address and port across all server blocks; for other sites on the same IP uselisten 443 quic;without it.add_headerin alocationreplaces all headers inherited from the server block, soAlt-Svcis repeated in the static files location.- The browser makes the first request over TCP, sees
Alt-Svcand switches to HTTP/3 for the next ones. That is why the first load of a new visitor is still HTTP/2.
The network
# Firewall: QUIC is UDP sudo ufw allow 443/udp # Larger UDP buffers for QUIC, in /etc/sysctl.d/99-quic.conf: # net.core.rmem_max = 7500000 # net.core.wmem_max = 7500000 sudo sysctl --system sudo nginx -t && sudo systemctl reload nginx
If the server is behind a cloud firewall or a load balancer, UDP 443 must be open there too; this is the most common reason why HTTP/3 “does not work” although the configuration is right.
Check
In Chrome DevTools, the Network tab with the “Protocol” column shows h3 after a reload. From the command line (with a curl built with HTTP/3 support):
curl -sI --http3 https://example.com/ | head -n 1 # HTTP/3 200 curl -sI https://example.com/ | grep -i alt-svc # the header is sent
NOTE: Leave TLS 0-RTT (ssl_early_data) off for WordPress. Early data can be replayed by an attacker, so it is only safe for requests that change nothing, and WordPress does not check for it: a replayed POST to admin-ajax.php or the checkout would be processed twice. The gain from HTTP/3 comes from the faster handshake and the absence of head-of-line blocking anyway.