fastcgi_buffer_size
Sets the buffer size for reading the first part of a FastCGI response.
Description
The fastcgi_buffer_size directive specifies the size of the buffer used to read the header of FastCGI responses from the backend server. When NGINX communicates with a FastCGI application, it buffers the response header to handle it effectively before transferring the body. An appropriately sized buffer can improve the performance of your NGINX configuration by ensuring that headers fit into the buffer without requiring multiple reads, thus reducing latency.
The buffer size is defined in the context of http, server, or location blocks, allowing granular control based on the level of configuration needed. It accepts an argument that specifies size values, such as 16k or 32. If the buffer is not large enough to hold the header data, NGINX may switch to a separate buffer for the body, which could result in increased response times or resource usage. Ensuring that the fastcgi_buffer_size is aligned with the expected response sizes from your FastCGI applications is crucial for optimal performance.
Config Example
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_buffer_size 32k;
include fastcgi_params;
}If the specified buffer size is too small, it can lead to additional overhead as NGINX reads the response in multiple parts.
Adjusting the buffer size without testing can adversely affect performance; always benchmark changes.