proxy_buffers

The `proxy_buffers` directive sets the number and size of buffers used for reading the response from a proxied server. — NGINX HTTP Core

proxy_buffers
httpserverlocation
Синтаксисproxy_buffers number size;
По умолчанию4 8k
Контекстhttp, server, location
МодульNGINX HTTP Core
Аргументы2

Описание

The `proxy_buffers` directive is essential in controlling how NGINX interacts with upstream servers during reverse proxying. It specifies the number and size of buffers allocated to hold the received data from the proxied server before sending it to the client. Each buffer is used to store segments of the response, allowing NGINX to aggregate data efficiently before delivery. The directive accepts two parameters: the number of buffers and the size of each buffer, specified in bytes. For example, a configuration of `proxy_buffers 8 16k;` means that NGINX will allocate eight buffers, each capable of holding 16 kilobytes of data. When a request is made to NGINX that involves upstream communication (such as with a backend web server), the response is handled in these buffers. If the upstream response exceeds the total size of the allocated buffers, NGINX will write the excess data directly to the client, bypassing the buffers. This is crucial for maintaining performance under load, as it helps to avoid memory overload by controlling the amount of data buffered at once. Additionally, if the buffers are not large enough, it may lead to excessive writes to the client, affecting throughput.

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

location / {
    proxy_pass http://backend;
    proxy_buffers 8 16k;
}

Ensure that the total buffer size is sufficient to handle the expected response size; otherwise, large responses may cause performance degradation.

Overly large buffers can lead to increased memory usage, which may not be ideal for low-resource environments.