client_body_buffer_size

The `client_body_buffer_size` directive sets the buffer size for reading the client request body into memory.

Syntaxclient_body_buffer_size size;
Default16k
Contexthttp, server, location
Arguments1

Description

The client_body_buffer_size directive specifies the maximum size of the buffer that NGINX will use to read the client request body. If the body exceeds this size, NGINX will write it to a temporary file, which can help manage memory usage and improve performance by allowing larger uploads without exhausting memory resources. The directive can be set within http, server, or location contexts, allowing for flexible configuration based on specific application needs.

When a request body is received, NGINX checks the size of the request against the specified client_body_buffer_size. If the size is within the limit, the body is buffered in memory; otherwise, it is stored in a disk file. This behavior is crucial for applications that handle file uploads or large payloads, as setting an appropriate buffer size can optimize both memory consumption and processing speed. The value can be specified in bytes, kilobytes (k), megabytes (m), etc., thereby allowing fine-tuning based on the expected size of incoming requests.

This directive is commonly used in conjunction with other related configurations, such as client_max_body_size, which specifies the maximum allowable size for a client request body overall. This further ensures that resources are managed appropriately, preventing abuse by excessively large uploads.

Config Example

http {
    client_body_buffer_size 32k;
}

Setting a very low buffer size may lead to excessive disk writes for larger bodies, affecting performance.

If client_max_body_size is lower than client_body_buffer_size, it can lead to unexpected behavior for larger requests.

← Back to all directives