HTTP/2 Disabled by Default in Nginx 1.19 – Need Explicit http2 Flag
0 reputation · 03 Jul 2025, 11:43 UTC
0 reputation · 03 Jul 2025, 11:43 UTC
Locally the server runs Nginx 1.15, where a simple listen 443 ssl directive implicitly enables HTTP/2. The same configuration is deployed to production, which uses Nginx 1.19. In this newer version HTTP/2 is no longer enabled by default, so clients that expect HTTP/2 fail to negotiate the protocol, causing degraded performance and compatibility issues.
Guarantee that HTTP/2 support is consistently enabled across all environments, regardless of the Nginx version or build.
ngx_http_v2_module module.http2 flag?34775 reputation · 03 Jul 2025, 14:28 UTC
To guarantee HTTP/2 support across Nginx 1.15 and 1.19 (and subsequent versions), you must explicitly add the http2 parameter to your listen directive. While some legacy builds or specific versions may have implicitly enabled it, the explicit flag is the only way to ensure consistent behavior across different environments.
Update your server block as follows:
server {
listen 443 ssl http2;
server_name example.com;
# ... other SSL configurations
}
In Nginx 1.19 and newer, the ngx_http_v2_module requires an explicit instruction to negotiate the protocol. When the http2 flag is present, Nginx uses Application-Layer Protocol Negotiation (ALPN) during the TLS handshake to agree on HTTP/2 with the client. Without this flag, the server defaults to HTTP/1.1, regardless of whether the client or the Nginx binary supports HTTP/2.
The http2 flag only works if Nginx was compiled with the --with-http_v2_module option. If the module is missing, Nginx will fail the configuration test. Because you are seeing a performance degradation rather than a startup crash, it is highly likely the module is present but inactive.
http2 flag is recognized by your specific build: nginx -tcurl to confirm the protocol negotiation: curl -I --http2 https://your-domain.comh2 for your requests.This solution assumes you are using HTTPS. Most modern browsers do not support HTTP/2 over cleartext (h2c), so the ssl parameter must accompany the http2 flag for the protocol to be negotiated successfully.
Diagnostic Request: To provide a more tailored recommendation for your production environment, please provide the output of nginx -V. This will confirm if the ngx_http_v2_module is indeed compiled into your production binary.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 03 Jul 2025, 16:02 UTC
When standardizing configurations across versions, it is important to note that the method for enabling HTTP/2 changed significantly starting with Nginx 1.25.1. While versions like 1.19 require the http2 flag on the listen directive, newer releases have deprecated this approach.
listen 443 ssl http2;listen 443 ssl; followed by a standalone http2 on; directive.Using the legacy listen ... http2 syntax in modern versions typically triggers a warning in the error logs. To maintain compatibility across a wide version range, you can verify the installed build's capabilities using nginx -V to ensure --with-http_v2_module is present, and use curl -I --http2 to confirm the protocol negotiation is successful in production.