$limit_rate

$limit_rate controls the maximum transfer rate for a response, effectively throttling bandwidth usage per connection. — NGINX Core (HTTP)

$limit_rate NGINX Core (HTTP)

Description

The `$limit_rate` variable in NGINX is used to limit the transfer speed for responses sent to clients. By adjusting this variable, administrators can ensure a maximum bandwidth consumption from a specific connection, which can be particularly useful in scenarios where managing server resources becomes crucial, such as during high traffic periods. The variable can be set to a specific byte value or it can derive its value from other variables, allowing flexible configurations depending on the needs of the application. This variable can be set dynamically, depending on various conditions within the configuration, such as IP addresses or specific request characteristics. The default state has `$limit_rate` set to zero, meaning there is no limit on the transfer speed. If set value is greater than zero, NGINX will apply the limitation per request and adjust the speed accordingly, which might significantly impact user experience if the rate is set too low. Commonly, values are given in bytes per second; for example, setting it to `1048576` would restrict the rate to `1MB/s`.

Config Example

http {
    server {
        location / {
            # Limit transfer rate
            limit_rate 500k;
        }
    }
}

Subsystem

http

Cacheable

No

Contexts

http, server, location, if

If set to zero, it bypasses any rate limiting and allows full bandwidth usage.

Using `$limit_rate` in conjunction with other rate limiting directives can lead to confusion if not configured correctly.

Ensure to adjust the limit rate according to server capacity and expected traffic patterns to avoid an unsatisfactory user experience.