http2_body_preread_size

The http2_body_preread_size directive sets the maximum size of the HTTP/2 request body that can be read and buffered in advance before processing.

Syntaxhttp2_body_preread_size size;
Defaultnone
Contexthttp, server
Arguments1

Description

The http2_body_preread_size directive is used to configure the maximum size of the HTTP/2 request body that can be read and temporarily stored in memory (buffered) prior to being handed off to the request processing handler in NGINX. This can be particularly beneficial for applications where early validation of the request body is needed before fully handling it.

When a request comes in via the HTTP/2 protocol, buffering a portion of the request body allows NGINX to analyze or validate the content, such as checking for specific headers or ensuring the body conforms to expected data formats. Setting a proper size for http2_body_preread_size helps optimize memory usage and performance since a very large value can lead to unnecessary memory consumption, while a very small value might restrict the ability to read larger requests efficiently.

The directive takes a size value as its argument, which can be specified in bytes (e.g., 1k, 2m) to define the maximum amount of data to buffer. Adjusting this value according to the specifics of the application’s requirements and the anticipated request sizes is essential for optimal NGINX performance and resource management.

Config Example

http {
    http2_body_preread_size 64k;
}

Ensure the specified buffer size is adequate for the expected request sizes, as an insufficient size may lead to processing errors.

Be cautious of resource limitations; setting the size too high can cause increased memory usage, potentially leading to application instability.

← Back to all directives