Migration Guide: HTTP/1.1 to HTTP/2
Step-by-step guide for migrating from HTTP/1.1 to HTTP/2. Covers TLS setup, server configuration, removing HTTP/1.1 workarounds, and testing verification.
Detailed Explanation
Migrating from HTTP/1.1 to HTTP/2
Migrating to HTTP/2 is one of the easiest performance wins for most websites. The protocol is backward-compatible, universally supported, and requires minimal application changes.
Prerequisites
- TLS is required: All browsers require HTTPS for HTTP/2. If you are still serving HTTP, set up TLS first.
- TLS 1.2 or later: HTTP/2 requires TLS 1.2+ with ALPN support.
- Modern server software: Nginx 1.9.5+, Apache 2.4.17+, Caddy (any version), Node.js 8.4+.
Server Configuration
Nginx:
server {
listen 443 ssl http2;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
ssl_protocols TLSv1.2 TLSv1.3;
}
Apache:
Protocols h2 h2c http/1.1
Caddy: HTTP/2 is enabled by default with automatic TLS.
Remove HTTP/1.1 Workarounds
After enabling HTTP/2, remove these optimizations that become counterproductive:
- Domain sharding: Multiple subdomains to bypass connection limits. HTTP/2 uses one connection — sharding adds DNS lookups and prevents connection reuse.
- Image sprites: Combining images into one file. Individual images are more efficient with multiplexing and have better caching.
- CSS/JS concatenation: Merging all scripts into one file. Smaller files cache independently and load in parallel.
- Inlining: Embedding CSS/JS in HTML. Separate files can be cached and shared across pages.
Testing
- Open Chrome DevTools > Network tab
- Right-click the column headers and enable "Protocol"
- Load your page — look for "h2" in the protocol column
- Verify that all resources load correctly
Common Pitfalls
- Forgetting ALPN: Without ALPN, the browser cannot negotiate HTTP/2 during the TLS handshake
- Proxy interference: If a reverse proxy does not support HTTP/2, it may downgrade connections
- Connection coalescing: HTTP/2 may reuse a connection for different hostnames sharing the same IP and certificate
Use Case
Website operators still using HTTP/1.1 should migrate to HTTP/2 as a first step. The performance improvement is immediate and requires no application code changes. Teams that have already optimized for HTTP/1.1 with domain sharding and concatenation should plan to remove those workarounds after migration.