upload_merge_buffer_size
Sets the buffer size for merging file upload data during multipart form uploads.
Description
The upload_merge_buffer_size directive in the NGINX upload module defines the size of the buffer used to merge uploaded file data. When handling multipart/form-data submissions, especially those with multiple file parts or resumable uploads, NGINX may need to temporarily store and process chunks of uploaded data. The merging process ensures that incoming data is appropriately formatted and assembled before being processed or saved. A larger buffer size can improve performance by reducing the frequency of memory reallocations which occur when dealing with large files or many concurrent uploads, but it might also increase memory usage per connection.
The parameter for this directive is specified in bytes, and setting it to a higher value allows for larger chunks of incoming data to be held in memory at once. However, it's important to strike a balance since excessively high values could lead to increased memory consumption, especially under heavy load with many concurrent uploads. Proper tuning of this directive based on expected upload sizes and traffic patterns can yield optimal results.
This directive can be used in various contexts including http, server, and location, allowing for flexibility in configuration depending on the specific needs of the application, such as different upload requirements for different locations or servers.
Config Example
http {
server {
location /upload {
upload_pass /upload_handler;
upload_merge_buffer_size 2m;
upload_store /tmp/uploads;
}
}
}Setting the buffer size too high may exhaust server memory under load.
The directive does not take effect until the NGINX worker processes are reloaded.
Misconfiguration can lead to fragmented or incomplete data uploads.