proxy_request_buffering

The `proxy_request_buffering` directive controls whether NGINX buffers the request body for proxied requests. — NGINX HTTP Core

proxy_request_buffering
httpserverlocation
Синтаксисproxy_request_buffering on | off;
По умолчаниюon
Контекстhttp, server, location
МодульNGINX HTTP Core
Аргументыflag

Описание

The `proxy_request_buffering` directive in NGINX determines how the request body of proxied requests is handled, specifically whether it is buffered before sending to the proxied server. By default, when `proxy_request_buffering` is enabled (which is often the case), NGINX will read the entire request body into memory or temporary files, depending on its size, before forwarding it to the upstream server. This allows NGINX to handle certain scenarios more effectively, such as rewriting headers or modifying request data based on configurations applied before proxying. When set to `off`, request body buffering is disabled, meaning that data is passed to the upstream server as it is received from the client. This can be useful for scenarios involving large files or streaming, where buffering would be inefficient or impractical. However, it may increase loading times if not handled properly and can complicate error handling since the upstream server may not have the complete request data until it is fully received from the client. Additionally, disabling buffering can lead to resource constraints under heavy loads, since the request body could be processed as a continual stream instead of an entire chunk, as typically would be the case when buffering is enabled.

Пример конфига

location /upload {
    proxy_pass http://backend;
    proxy_request_buffering off;
}

Ensure that the upstream server can handle streaming requests if buffering is disabled.

Be aware that disabling request buffering can complicate error handling and may impact performance under heavy load.