subs_buffers
The 'subs_buffers' directive specifies the number and size of buffers used for storing temporary data during string substitutions in NGINX responses.
Description
The 'subs_buffers' directive is part of the String Substitutions module for NGINX, which allows the replacement of specified strings within the output response before it reaches the client. This directive helps control how the module allocates buffers that it uses for processing substitution operations. The two parameters it takes dictate the number of buffers and their sizes, respectively. Properly tuning these values can lead to more efficient memory usage and improved performance during dynamic content substitution.
The first argument denotes the number of buffers to allocate, while the second specifies the size of each buffer. With these buffers, the module can efficiently handle string replacements on incoming HTTP responses by reading the data in manageable chunks, thus avoiding potential memory exhaustion when dealing with large response bodies. For example, by setting 'subs_buffers 8 16k;', you would allocate 8 buffers, each of 16 kilobytes. This can be particularly useful for high-traffic environments or when processing responses with significant embedded variable data.
When using this directive, it is essential to consider the expected size of responses and number of simultaneous connections, as an inappropriate configuration could lead to performance bottlenecks or excessive memory consumption. Experimentation may be necessary to find the optimal settings for a specific use case.
Config Example
location / {
subs_buffers 8 16k;
subs_filter a.example.com b.example.com;
}Setting too many buffers or excessively large buffer size can lead to increased memory usage.
If buffers are insufficient, NGINX may fail to process larger responses correctly, causing substitution errors or incomplete output.