nginx runtime_error ai_generated true

proxy request body too large for buffering

ID: nginx/proxy-request-body-too-large-for-buffering

Also available as: JSON · Markdown · 中文
85%Fix Rate
88%Confidence
1Evidence
2024-03-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
nginx 1.24.0 active
nginx 1.22.1 active
nginx 1.20.2 active

Root Cause

The upstream server expects a Content-Length header, but the request body exceeds proxy_buffer_size and buffering is disabled, causing nginx to fail to forward the request.

generic

中文

上游服务器期望 Content-Length 头部,但请求体超过 proxy_buffer_size 且缓冲被禁用,导致 nginx 无法转发请求。

Official Documentation

https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size

Workarounds

  1. 85% success Increase proxy_buffer_size to accommodate the expected request body size, e.g., add 'proxy_buffer_size 8k;' or larger in the location or http block.
    Increase proxy_buffer_size to accommodate the expected request body size, e.g., add 'proxy_buffer_size 8k;' or larger in the location or http block.
  2. 90% success Enable proxy request buffering by setting 'proxy_request_buffering on;' (default) and ensure proxy_buffer_size is at least the size of typical request bodies.
    Enable proxy request buffering by setting 'proxy_request_buffering on;' (default) and ensure proxy_buffer_size is at least the size of typical request bodies.
  3. 75% success If the upstream can handle chunked transfer encoding, disable the Content-Length requirement by adding 'proxy_http_version 1.1;' and 'proxy_set_header Connection "";' to allow chunked requests.
    If the upstream can handle chunked transfer encoding, disable the Content-Length requirement by adding 'proxy_http_version 1.1;' and 'proxy_set_header Connection "";' to allow chunked requests.

中文步骤

  1. Increase proxy_buffer_size to accommodate the expected request body size, e.g., add 'proxy_buffer_size 8k;' or larger in the location or http block.
  2. Enable proxy request buffering by setting 'proxy_request_buffering on;' (default) and ensure proxy_buffer_size is at least the size of typical request bodies.
  3. If the upstream can handle chunked transfer encoding, disable the Content-Length requirement by adding 'proxy_http_version 1.1;' and 'proxy_set_header Connection "";' to allow chunked requests.

Dead Ends

Common approaches that don't work:

  1. 90% fail

    client_max_body_size only limits the client request body size; the proxy buffer error is about how nginx forwards the body to upstream.

  2. 70% fail

    Disabling buffering forces nginx to hold the entire body in a single buffer; if the body exceeds proxy_buffer_size, the error persists.

  3. 95% fail

    proxy_buffering controls response buffering from upstream, not request body buffering to upstream.