{
  "id": "nginx/upstream-sent-invalid-content-length-zero",
  "signature": "upstream sent invalid content-length: 0 while reading response header from upstream",
  "signature_zh": "上游服务器在读取响应头时发送了无效的内容长度：0",
  "regex": "upstream sent invalid content-length: 0 while reading response header from upstream",
  "domain": "nginx",
  "category": "protocol_error",
  "subcategory": null,
  "root_cause": "The upstream server sent a Content-Length header with value 0 but included a response body, violating HTTP/1.1 specifications and causing nginx to reject the response.",
  "root_cause_type": "generic",
  "root_cause_zh": "上游服务器发送了值为 0 的 Content-Length 头部，但包含了响应体，违反了 HTTP/1.1 规范，导致 nginx 拒绝响应。",
  "versions": [
    {
      "version": "nginx 1.24.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "nginx 1.22.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "nginx 1.20.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "nginx 1.18.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The error is about header semantic validity, not buffer size.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "proxy_set_header modifies request headers, not response headers.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The error occurs during header parsing, which is independent of response buffering.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add 'proxy_ignore_headers Content-Length;' in the location block to make nginx ignore the Content-Length header from upstream, allowing the response to be processed based on chunked encoding or connection close.",
      "success_rate": 0.85,
      "how": "Add 'proxy_ignore_headers Content-Length;' in the location block to make nginx ignore the Content-Length header from upstream, allowing the response to be processed based on chunked encoding or connection close.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Fix the upstream application to not send Content-Length: 0 when there is a body; use chunked transfer encoding instead by setting 'Transfer-Encoding: chunked' and omitting Content-Length.",
      "success_rate": 0.9,
      "how": "Fix the upstream application to not send Content-Length: 0 when there is a body; use chunked transfer encoding instead by setting 'Transfer-Encoding: chunked' and omitting Content-Length.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the upstream is a legacy server that cannot be changed, use a proxy module like 'ngx_http_lua_module' to strip the Content-Length header: 'header_filter_by_lua_block { if ngx.header[\"Content-Length\"] == 0 then ngx.header[\"Content-Length\"] = nil end }'",
      "success_rate": 0.75,
      "how": "If the upstream is a legacy server that cannot be changed, use a proxy module like 'ngx_http_lua_module' to strip the Content-Length header: 'header_filter_by_lua_block { if ngx.header[\"Content-Length\"] == 0 then ngx.header[\"Content-Length\"] = nil end }'",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Add 'proxy_ignore_headers Content-Length;' in the location block to make nginx ignore the Content-Length header from upstream, allowing the response to be processed based on chunked encoding or connection close.",
    "Fix the upstream application to not send Content-Length: 0 when there is a body; use chunked transfer encoding instead by setting 'Transfer-Encoding: chunked' and omitting Content-Length.",
    "If the upstream is a legacy server that cannot be changed, use a proxy module like 'ngx_http_lua_module' to strip the Content-Length header: 'header_filter_by_lua_block { if ngx.header[\"Content-Length\"] == 0 then ngx.header[\"Content-Length\"] = nil end }'"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headers",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.8,
  "resolvable": "partial",
  "first_seen": "2024-05-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}