How to Fix Nginx HTTP/2 Not Working Error
In this tutorial, you'll learn about How to Fix Nginx HTTP/2 Not Working Error. We cover key concepts, practical examples, and best practices.
Nginx responds with HTTP/1.1 instead of HTTP/2 even though http2 is configured — browsers show h2 in the :scheme pseudo-header is not working or the ALPN negotiation fails.
The Problem
$ curl -I --http2 http://localhost/
# Response uses HTTP/1.1 instead of HTTP/2
HTTP/1.1 200 OK
Step-by-Step Fix
Step 1: Enable HTTP/2 correctly
# Correct for Nginx 1.25+
server {
listen 443 ssl;
http2 on; # or http2 on;
# ...
}
# Correct for older Nginx (< 1.25)
server {
listen 443 ssl http2;
# ...
}
Step 2: Verify HTTP/2 is compiled in
nginx -V 2>&1 | grep -o http_v2
Expected: http_v2
Step 3: Check ALPN configuration
ssl_protocols TLSv1.2 TLSv1.3; # HTTP/2 requires TLSv1.2+
ssl_ciphers HIGH:!aNULL:!MD5;
Step 4: Test with curl
curl -v --http2 https://example.com/ 2>&1 | grep -i "alpn\|http2"
Expected:
* ALPN: offers h2,http/1.1
* ALPN: server accepted h2
* Using HTTP/2
Step 5: Test with openssl
openssl s_client -connect localhost:443 -alpn h2 -tlsextdebug
Prevention Tips
- Use OpenSSL 1.0.2+ for ALPN support (required for HTTP/2)
- Enable HTTP/2 only on HTTPS (browsers do not support h2c)
- Test with
curl --http2-prior-knowledgefor clear-text HTTP/2 - Verify HTTP/2 with Chrome DevTools Network tab (Protocol column)
Common Mistakes with http2 not working
- Forgetting
deriving (Show, Eq)on custom data types needed for debugging - Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists
These mistakes appear frequently in real-world NGINX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro