scgi_buffers
The `scgi_buffers` directive sets the number and size of buffers used for SCGI responses.
Description
The scgi_buffers directive is designed for optimizing the handling of SCGI (Simple Common Gateway Interface) responses in NGINX. It specifies the number of buffers and their size that the server will use to store the response from the SCGI server before passing it on to the client. By configuring the buffers appropriately, you can balance memory usage and performance; larger buffers can help in reducing the number of reads from the SCGI server, potentially speeding up response delivery, especially for large responses.
The directive takes two parameters: the first denotes the number of buffers, while the second indicates the size of each buffer. The buffers are allocated per request, which means that with a higher number, the server can handle multiple concurrent connections more efficiently. Care should be taken not to allocate too much memory, as this can lead to increased memory consumption and possible performance degradation.
The scgi_buffers directive can be set in the http, server, or location contexts, providing flexibility in configuration based on the scaling needs of your application and its specific endpoints. This directive is complementary to other buffer-related settings in NGINX and can be tuned alongside them for optimal performance.
Config Example
server {
listen 80;
location /app {
scgi_pass localhost:4000;
scgi_buffers 8 16k;
}
}Setting the buffer size too small may result in incomplete responses if the data exceeds the buffer size.
If you set too many buffers, it may lead to increased memory usage, especially under high load conditions.