upload_limit_rate
The `upload_limit_rate` directive controls the maximum upload speed for file uploads in NGINX.
Description
The upload_limit_rate directive is utilized to manage the rate of file uploads to a server. This directive allows configuration of a bandwidth limit on incoming file uploads, expressed in bytes per second. By setting this limit, administrators can prevent overwhelming server resources during peak upload times by throttling the rate at which data can be received from clients. The directive can be specified with a value such as 1m to define a maximum upload rate of 1 megabyte per second, or in other byte-scale specifications like 500k for kilobytes.
This directive can be used in various contexts including http, server, location, and if inside a location block. The setting affects all uploads processed under the defined block, ensuring that each upload adheres to the specified rate limit. Additionally, this can be particularly useful for improving the user experience in high-load scenarios, as it helps to distribute bandwidth more evenly and can prevent server overload from heavy upload activities.
It's important to note that this directive does not limit the amount of data being uploaded; it merely controls the speed at which it’s uploaded, thereby affecting the time it takes for uploads to complete. Consequently, users may experience longer upload times rather than restricted access to upload capabilities.
Config Example
location /upload {
upload_pass /handle_upload;
upload_store /tmp/uploads;
upload_limit_rate 1m;
}Specifying a very low rate may lead to timeouts or failed uploads, especially for large files.
Be cautious when using multiple upload_limit_rate directives in nested contexts, as the most specific one takes precedence, which may lead to unexpected behavior.