nginx
protocol_error
ai_generated
true
upstream sent invalid Connection header while reading response header from upstream
ID: nginx/upstream-sent-invalid-connection-header
90%Fix Rate
85%Confidence
1Evidence
2024-06-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| nginx 1.24.0 | active | — | — | — |
| nginx 1.25.3 | active | — | — | — |
| nginx 1.26.0 | active | — | — | — |
Root Cause
Upstream server returns a malformed or non-compliant 'Connection' header (e.g., multiple values, invalid token) that nginx rejects.
genericOfficial Documentation
https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headersWorkarounds
-
90% success Use proxy_ignore_headers to ignore the Connection header from upstream: location / { proxy_pass http://upstream; proxy_ignore_headers Connection; }
Use proxy_ignore_headers to ignore the Connection header from upstream: location / { proxy_pass http://upstream; proxy_ignore_headers Connection; } -
95% success Fix the upstream application to emit a valid Connection header (e.g., 'close' or 'keep-alive' only, no duplicates). For example, in a Node.js app: res.setHeader('Connection', 'keep-alive'); // Remove any duplicate or malformed Connection headers
Fix the upstream application to emit a valid Connection header (e.g., 'close' or 'keep-alive' only, no duplicates). For example, in a Node.js app: res.setHeader('Connection', 'keep-alive'); // Remove any duplicate or malformed Connection headers
中文步骤
Use proxy_ignore_headers to ignore the Connection header from upstream: location / { proxy_pass http://upstream; proxy_ignore_headers Connection; }Fix the upstream application to emit a valid Connection header (e.g., 'close' or 'keep-alive' only, no duplicates). For example, in a Node.js app: res.setHeader('Connection', 'keep-alive'); // Remove any duplicate or malformed Connection headers
Dead Ends
Common approaches that don't work:
-
Add proxy_set_header Connection '';
80% fail
This only affects request headers sent to upstream, not response headers from upstream.
-
Clear nginx cache
100% fail
Caching does not cause or fix header validation issues.
-
Upgrade nginx to latest version
60% fail
The issue is usually in the upstream application, not nginx itself.