nginx
protocol_error
ai_generated
true
upstream sent invalid Transfer-Encoding: chunked with Content-Length while reading response header from upstream
ID: nginx/upstream-sent-invalid-transfer-encoding-chunked-with-content-length
90%Fix Rate
88%Confidence
1Evidence
2025-05-10First 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 sends both Content-Length and Transfer-Encoding: chunked headers in the same response, which is invalid per HTTP/1.1.
genericOfficial Documentation
https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headersWorkarounds
-
85% success Use proxy_ignore_headers to ignore one of the conflicting headers. Example to ignore Content-Length: location / { proxy_pass http://upstream; proxy_ignore_headers Content-Length; }
Use proxy_ignore_headers to ignore one of the conflicting headers. Example to ignore Content-Length: location / { proxy_pass http://upstream; proxy_ignore_headers Content-Length; } -
95% success Fix the upstream application to send only one of the headers. For example, in a Node.js Express app: app.get('/data', (req, res) => { res.removeHeader('Content-Length'); res.setHeader('Transfer-Encoding', 'chunked'); res.send('hello'); });
Fix the upstream application to send only one of the headers. For example, in a Node.js Express app: app.get('/data', (req, res) => { res.removeHeader('Content-Length'); res.setHeader('Transfer-Encoding', 'chunked'); res.send('hello'); });
中文步骤
Use proxy_ignore_headers to ignore one of the conflicting headers. Example to ignore Content-Length: location / { proxy_pass http://upstream; proxy_ignore_headers Content-Length; }Fix the upstream application to send only one of the headers. For example, in a Node.js Express app: app.get('/data', (req, res) => { res.removeHeader('Content-Length'); res.setHeader('Transfer-Encoding', 'chunked'); res.send('hello'); });
Dead Ends
Common approaches that don't work:
-
Remove Content-Length header from nginx config using proxy_set_header
95% fail
proxy_set_header affects request headers to upstream, not response headers from upstream.
-
Enable chunked_transfer_encoding off; in nginx
80% fail
This directive controls nginx's own encoding, not upstream response validation.
-
Increase proxy_buffer_size
100% fail
Header size is not the issue; header validity is.