Dump the code

Nginx buffers

Created 10 months ago
Posted By admin
3min read
In the context of Nginx, a buffer refers to a temporary storage area used to hold data during the processing of a request or response. Nginx uses buffers to efficiently handle data between different stages of the request processing pipeline. Buffers are crucial for handling large amounts of data, such as when serving static files, proxying requests, or handling fast upstream connections.

The proxy_buffers directive, along with related directives like proxy_buffer_size and proxy_busy_buffers_size, is typically placed within a location block in your NGINX configuration. The location block is used to define the configuration for a specific URI or a group of URIs.

There are a few types of buffers in Nginx:

Client Body Buffer

This buffer is used to store the client request body when Nginx is acting as a reverse proxy or handling large file uploads. It prevents the web server from reading the entire request body into memory at once, which can be especially important for handling large file uploads.

client_body_buffer_size 10K;

Proxy Buffering 

When Nginx acts as a reverse proxy, it buffers responses from the upstream server before sending them to the client. This can help in situations where the upstream server is slow or the client connection is slow, allowing Nginx to optimize the data transfer.

proxy_buffering on;
proxy_buffer_size 4k;
proxy_buffers 4 8k;
  • proxy_buffering: Enables or disables buffering of responses from the proxied server.
  • proxy_buffer_size: Sets the size of the buffer used for reading the first part of the response received from the proxied server.
  • proxy_buffers: Sets the number and size of the buffers used for reading a response from the proxied server.

FastCGI Buffering

Similar to proxy buffering, Nginx can buffer responses when communicating with a FastCGI server.

fastcgi_buffering on;
fastcgi_buffer_size 4k;
fastcgi_buffers 64 4k;
  • fastcgi_buffering: Enables or disables buffering of responses from the FastCGI server.
  • fastcgi_buffer_size: Sets the size of the buffer used for reading the first part of the response received from the FastCGI server.
  • fastcgi_buffers: Sets the number and size of the buffers used for reading a response from the FastCGI server.

These buffer configurations can be adjusted based on the specific requirements and characteristics of your web application and server environment.
Topics

Mastering Nginx

27 articles

Bash script

2 articles

Crontab

2 articles