limit_rate

The `limit_rate` directive restricts the bandwidth for a response sent to a client.

Syntaxlimit_rate rate;
Defaultnone
Contexthttp, server, location, if in location
Arguments1

Description

The limit_rate directive allows you to set a limit on the request rate for responding clients. This can be particularly useful in preventing a single user from consuming excessive server resources or bandwidth, which could otherwise degrade the performance for other users. The directive accepts a single argument that specifies the maximum transfer rate in bytes per second. You can include a suffix such as 'k' for kilobytes or 'm' for megabytes to simplify the configuration.

When applied, limit_rate influences the response by controlling how much data is sent during an interval, effectively implementing a throttle on the outgoing traffic. This throttle is active during the response phase of the request processing, which means it is effective in server directives such as http, server, and location contexts, as well as within if statements in a location. This can be particularly advantageous for serving large files or during peak traffic, allowing fair bandwidth distribution among clients.

If the limit_rate value is exceeded by the current download rate, NGINX will pause the transmission of data to respect this limit, resulting in a smoother experience across all users by ensuring that no single client can monopolize server resources.

Config Example

location /downloads {
    limit_rate 100k;
}

Using limit_rate inside an if directive may lead to unexpected behavior due to the complexities of NGINX's configuration processing.

The rate limit only applies to transmitted data; it does not affect the handling of incoming requests.

Overly restrictive rate limits can lead to increased response times for clients.

← Back to all directives