nginx,

Nginx proxy and 'an upstream response is buffered to a temporary file' warning

May 08, 2022 · 1 min read · Post a comment

In today’s Nginx log message of the week, we got the following warning:

2022/05/02 08:03:16 [warn] 31447#0: an upstream response is buffered to a temporary file /var/lib/nginx/proxy/1/34/0000000341 while reading upstream.

So, what happens is Nginx acts as a proxy and tries to buffer a response because the client can’t receive it on it’s side fast enough. Obviously, Nginx buffers the response at once and writes a warning message in the logs, since the response is larger than the currently configured memory buffers.

Prerequisites

  • Nginx

Possible solution(s)

Increase buffers

Increase proxy_buffers and proxy_buffers_size parameters. For instance:

proxy_buffers 16 16k;
proxy_buffer_size 16k;

According to the official docs the default values for proxy_buffers are 8 4k/8k (depending on the platform), and 4k/8k for proxy_buffers_size. It is determined by the default memory page size tho (to find it out, just run getconf PAGESIZE).

This is a quick fix indeed, if you don’t know what you are doing lol. Albeit you could play around the values, I would suggest to find out the maximum and average response sizes first. Check out Tweaking Nginx proxy_buffers parameters for more info. Then, adjust the values accordingly.

Disable buffering

Set proxy_buffering to off.

proxy_buffering off;

Default value is on. Setting it to off, will stream the response directly to the client. Not recommended though!

Ignore the warning

Least you can do is do nothing, but keep an eye on the key server performance metrics: CPU, disk I/O and memory.

Conclusion

If you need a fastcgi-related solution check How to resolve Nginx ‘an upstream response is buffered to a temporary file’. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.