How to Enable HTTP/2 (and HTTP/3): Nginx, Apache, CDN
Want faster loads? Turn on HTTP/2 and, if possible, HTTP/3. This guide shows how to enable both on Nginx, Apache, and common CDNs, how to check they work, and quick fixes if they don't.
Why HTTP/2 (and HTTP/3)?
HTTP/1.1 opens multiple connections and repeats headers. HTTP/2 multiplexes requests over one connection and compresses headers. HTTP/3 adds QUIC over UDP to avoid transport-level blocking. Result: faster loads, especially on mobile and high-latency links.
Quick checks: are they on?
- DevTools: Network tab > add "Protocol" column. Look for h2 or h3.
- CLI:
curl -I --http2 https://example.com
- HTTP/3:
curl -I --http3 https://example.com
(recent curl) - Waterfalls: Many files should start together on one connection.
Nginx: enable HTTP/2 (and HTTP/3)
server {
# HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
# Uncomment if your build supports QUIC
# listen 443 quic reuseport;
# add_header Alt-Svc 'h3=":443"; ma=86400' always;
server_name example.com;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d;
add_header Strict-Transport-Security "max-age=31536000" always;
# your SSL cert config here
}
Requirements: HTTP/2 module compiled in, TLS library with ALPN support. Most modern packages include both.
Apache: enable HTTP/2
# Load the module
LoadModule http2_module modules/mod_http2.so
# Enable globally or in a vhost
Protocols h2 http/1.1
# Optional: restrict to modern TLS
H2ModernTLSOnly on
Apache HTTP/3 support is experimental. Stick with HTTP/2 for production.
CDN: enable HTTP/2/3 (Cloudflare, CloudFront, Akamai, Fastly)
Most CDNs support HTTP/2 and HTTP/3. Turn them on for HTTPS traffic. Open UDP/443 if you run your own edge and want HTTP/3. If UDP is blocked, clients fall back to HTTP/2. The CDN to origin protocol is separate; use it if easy, but user impact comes from the edge.
Cloudflare
Dashboard > Speed > Optimization > HTTP/2 and HTTP/3 (enabled by default)
AWS CloudFront
Distribution settings > Supported HTTP Versions > HTTP/2 and HTTP/3
Fastly
Service configuration > Settings > HTTP/2 and HTTP/3 support
Verify + fallback behavior
Browsers negotiate automatically during TLS handshake using ALPN. If HTTP/3 fails (UDP blocked), they fall back to HTTP/2. If HTTP/2 fails (old server), they use HTTP/1.1. No manual intervention needed.
Check your setup:
- Modern browsers show h2/h3 in DevTools Protocol column
- Waterfall charts show parallel downloads on one connection
- H3 often helps mobile/lossy links more than desktop
Troubleshooting
HTTP/2 not working?
- Check if your server build includes the HTTP/2 module
- Verify TLS library supports ALPN (OpenSSL 1.0.2+)
- Ensure you're testing over HTTPS (browsers require it)
- Check if a proxy/load balancer is downgrading to HTTP/1.1
HTTP/3 not working?
- Verify UDP port 443 is open
- Check if your build supports QUIC
- Confirm Alt-Svc header is being sent
- Test from different networks (some block UDP)
FAQs
Do I need HTTPS for HTTP/2?
Yes. Browsers only use HTTP/2 over TLS.
Is HTTP/3 required?
No, but enable it when you can. Keep HTTP/2 as fallback.
How do I check if HTTP/2/3 is active?
Use DevTools' Protocol column, or run curl with --http2 or --http3.
Why didn't enabling HTTP/2 change much?
App slowness and network loss still apply. Cache and profile your app; use HTTP/3 for lossy links.