fastcgi_buffering

The `fastcgi_buffering` directive controls whether to buffer responses from FastCGI servers.

Syntaxfastcgi_buffering on | off;
Defaulton
Contexthttp, server, location
Argumentsflag

Description

The fastcgi_buffering directive, when set to on, enables the buffering of responses from FastCGI servers before they are sent to the client. This buffering mechanism allows NGINX to handle responses more efficiently by reading the entire response body from the FastCGI server into a buffer before forwarding it to the client. In contrast, when set to off, responses are passed to the client immediately upon being received, which can lead to increased responsiveness at the cost of resource management, especially under high load.

When the directive is set to on, NGINX uses several predetermined buffer sizes that can be adjusted using other directives such as fastcgi_buffers and fastcgi_buffer_size. This overall buffering strategy can lead to reduced latency for clients because NGINX can send larger chunks of data faster once the entire response is fetched, particularly useful for larger response bodies. However, buffering should be managed carefully; excessive buffering can lead to increased memory usage.

This directive can be configured at the http, server, or location context levels, allowing for flexible configuration based on specific needs. It is crucial to understand the implications of both settings (on vs. off) for optimal performance tuning of NGINX based on the application’s requirements.

Config Example

location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_buffering off;
    include fastcgi_params;
}

Setting fastcgi_buffering to off may lead to higher CPU usage as responses are passed directly to clients without buffering.

It is recommended to monitor memory usage when using fastcgi_buffering on, as large responses can consume significant memory resources.

← Back to all directives