proxy_buffer_size

Sets the buffer size for the response from the proxied server. — NGINX HTTP Core

proxy_buffer_size
httpserverlocation
Синтаксисproxy_buffer_size size;
По умолчанию4k or 8k, depending on the platform
Контекстhttp, server, location
МодульNGINX HTTP Core
Аргументы1

Описание

The `proxy_buffer_size` directive in NGINX allows you to define the size of the buffer used to hold the first part of the response received from the proxied server. This directive is particularly relevant when dealing with dynamic responses, such as those generated by scripts (PHP, Python, etc.), as it sets the maximum size of the response header that can be stored in the buffer before processing begins. If the response is larger than the specified size, NGINX will allocate more buffers, which can impact performance depending on the size of these buffers and the server configuration. In terms of parameter specification, `proxy_buffer_size` accepts a single argument that represents the buffer size and can specify values in bytes, kilobytes (k), or megabytes (m). For instance, `proxy_buffer_size 16k;` sets the buffer size to 16 kilobytes. This directive can be placed in the `http`, `server`, or `location` contexts, allowing for flexible configuration depending on the specific needs of your setup. It's important to note that the effective buffer size can be influenced by other directives such as `proxy_buffers`, which determines the total number of buffers allocated for a single response. When configuring `proxy_buffer_size`, consider the characteristics of your upstream server responses. If your upstream server frequently sends large headers, it may be prudent to increase this buffer size to prevent NGINX from reallocating buffers unnecessarily, which can lead to performance degradation. Therefore, strategic use of this directive can improve server efficiency and user experience by reducing response times.

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

location /api/ {
    proxy_pass http://backend;
    proxy_buffer_size 16k;
}

Setting the buffer size too low may cause response headers to be truncated, leading to unpredictable application behavior.

Be mindful of server memory limits; very large buffer sizes can lead to excessive memory usage if many concurrent connections occur.