Tag Archives: Nginx an upstream response is buffered to a temporary file

Nginx an upstream response is buffered to a temporary file,nginx502 Error

1.Error: warn:an upstream response is buffered to a temporary file

Solution: Add fastcgi_buffers 8 4K; fastcgi_buffer_size 4K;

2. a client request body is buffered to a temporary file

Solution: Add client_max_body_size 2050m; client_body_buffer_size 1024k;

Buffer mechanism of nginx:

For the response from the fastcgi server, nginx buffers it into memory and sends it to the client browser in turn. The size of the buffer is determined by fastcgi_ Buffers and fastcgi_ buffer_ Size is controlled by two values

For example, the configuration is as follows:

fastcgi_buffers      8 4K; fastcgi_buffer_size 4K;

fastcgi_ Buffers control nginx to create up to eight 4K buffers, while fastcgi controls nginx to create up to eight 4K buffers_ buffer_ Size is the size of the first buffer in response processing, which is not included in the former. So the total maximum memory buffer size that can be created is 8 * 4K + 4K = 36K. These buffers are generated dynamically according to the actual response size and are not created at one time. For example, for an 8K page, nginx will create 2 * 4K buffers

When the response is less than or equal to 36K, all data will be processed in memory. What if the response is greater than 36K?fastcgi_ That’s what temps do. The extra data will be temporarily written to the file and placed under this directory. At the same time, you will see a warning like this in error. Log

2010/03/13 03:42:22 [warn] 3994#0: *1 an upstream response is buffered to a temporary file /usr/local/nginx/fastcgi_temp/1/00/0000000001 while reading upstream, client: 192.168.1.111, server: www.xxx.cn, request: "POST /test.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xxx.cn", referrer: "http://xxx.cn/test.php"

Obviously, if the buffer is set too small, nginx will read and write to the hard disk frequently, which has a great impact on the performance, but it is not that the larger the better, which is meaningless