proxy_temp_file_write_size
The `proxy_temp_file_write_size` directive sets the size limit for writing temporary files when handling proxy responses.
Description
The proxy_temp_file_write_size directive in NGINX specifies the maximum size of data that can be written to temporary files for proxy responses. When a response from the proxied server is larger than this size, NGINX will buffer it in temporary files rather than in memory, which can be crucial for managing memory usage in high-load scenarios. The directive can help avoid out-of-memory situations by controlling how much response data can reside in memory before being offloaded to disk.
This directive accepts a single argument, which defines the size limit and can have values such as '1m' for one megabyte, '512k' for half a megabyte, etc. The context for this directive includes http, server, and location, giving users flexibility in configuring it based on the desired scope of the proxy settings. It is essential to consider the disk I/O impact when tuning this setting, especially on servers with limited resources or when serving large files frequently.
In practice, if the response size exceeds the configured limit, the proxy server will begin writing data to temporary files located in a specified directory, allowing the remaining processing to continue without overwhelming the server's memory. Administrators should monitor response sizes closely and adjust this setting accordingly to optimize performance and resource management.
Config Example
http {
proxy_temp_file_write_size 1m;
server {
location / {
proxy_pass http://backend;
}
}
}Setting proxy_temp_file_write_size too low may result in frequent writes to disk, affecting performance, especially under high load.
Ensure that the system has adequate disk space available for the temporary files; otherwise, it may result in errors during request handling.
Changing this directive in a running configuration might not affect ongoing requests; a reload or restart may be necessary.