Nginx Error Log: upstream response is buffered to a temporary file – Causes and Fix
When checking Nginx logs, you may occasionally come across a long warning: an upstream response is buffered to a temporary file. The site still loads normally, yet that line in error.log makes you wonder whether something is wrong with your configuration.
In short: this is not an error, but a standard notice saying that the backend response did not fit into Nginx’s RAM buffers, so the server temporarily spilled the remainder to a file on disk.
Why This Warning Appears
When Nginx acts as a reverse proxy in front of Apache, PHP-FPM, Node.js, or Python, it tries to read the upstream response into memory as fast as possible so the backend worker is freed immediately while Nginx finishes sending data to the client. By default, only a small amount of memory is allocated – typically proxy_buffer_size equals one memory page (4k or 8k), and proxy_buffers defaults to 8 4k or 8 8k.
Once an HTML page, JSON API payload, or file exceeds those buffers combined, Nginx writes the overflow into a temporary directory (such as /var/cache/nginx/proxy_temp) and logs a [warn] entry. For an occasional heavy request that is harmless, but under steady traffic extra disk writes increase I/O wait.
Method 1. Increase In-Memory Buffers (Recommended)
For most setups, it is better to enlarge RAM buffers to match your actual page sizes inside the http, server, or specific location block rather than disabling temporary files right away:
proxy_buffering on; proxy_buffer_size 16k; proxy_buffers 8 32k; proxy_busy_buffers_size 64k;
This allocates up to 256 KB of buffers per connection – plenty for large pages and API responses so Nginx stops hitting the disk.
A practical detail to keep in mind: if your backend is connected directly via FastCGI (PHP-FPM over fastcgi_pass) rather than proxy_pass, the proxy_* directives do not apply. In that case, configure the matching FastCGI settings inside your PHP block: fastcgi_buffer_size, fastcgi_buffers, and optionally fastcgi_max_temp_file_size.
Method 2. Disable Temp Files with proxy_max_temp_file_size 0
To silence the warning quickly, I used to add this line inside the http {} section of nginx.conf:
http {
proxy_max_temp_file_size 0;
}
With this setting, Nginx stops writing responses to disk – data that does not fit in RAM buffers is streamed gradually as the client reads it. However, as readers rightly pointed out in the comments, setting a hard zero has a trade-off: if a slow client downloads a large response, the backend worker stays tied up waiting for the transfer instead of being released immediately. Use proxy_max_temp_file_size 0 (or proxy_buffering off;) only when saving disk I/O matters more or when streaming responses directly.
Large Files and X-Accel-Redirect
If big archives, images, or video files are spilling into proxy_temp or fastcgi_temp, enlarging RAM buffers is the wrong fix – gigabytes should not be piped through Apache or PHP at all. Static assets should be served directly by Nginx, and for permission-checked downloads use X-Accel-Redirect: the backend verifies access and returns only an internal path pointing to an internal; location. That avoids proxy temp writes completely, frees the backend in milliseconds, and lets Nginx handle the transfer.
