nginx protocol_error ai_generated true

上游发送了无效的 chunked 传输编码

upstream sent invalid chunked transfer encoding while reading response body from upstream

ID: nginx/upstream-sent-invalid-chunked-transfer-encoding

其他格式: JSON · Markdown 中文 · English
88%修复率
82%置信度
1证据数
2024-06-20首次发现

版本兼容性

版本状态引入弃用备注
nginx/1.24.0 active
nginx/1.22.1 active
nginx/1.26.0 active

根因分析

上游服务器发送了格式错误的 chunked 响应(例如缺少 CRLF、无效的块大小),违反了 HTTP/1.1 的分块传输编码规则。

English

Upstream server sent a malformed chunked response (e.g., missing CRLF, invalid chunk size) that violates HTTP/1.1 chunked transfer encoding rules.

generic

官方文档

https://nginx.org/en/docs/http/ngx_http_upstream_module.html

解决方案

  1. Fix the upstream application to generate proper chunked encoding (e.g., in Go: ensure http.ResponseWriter uses default chunking correctly, avoid manual chunked writes).
  2. Disable chunked transfer encoding in upstream by setting Content-Length header in the response (e.g., in Node.js: res.setHeader('Content-Length', Buffer.byteLength(body)); res.end(body)).
  3. Use proxy_set_header Connection ''; to force HTTP/1.0 and avoid chunked encoding, then ensure upstream responds with Content-Length.

无效尝试

常见但无效的做法:

  1. 75% 失败

    Timeout does not fix malformed data; the error is structural, not timing-related.

  2. 65% 失败

    If upstream expects HTTP/1.1, this may break communication; also, nginx still parses chunked if upstream sends it.

  3. 90% 失败

    This directive does not exist in nginx; it is a common misconception.