http-limit-traffic-rate #

Limits the total download speed for all requests that share a key, such as one client IP address, across worker processes. Use it when limit_rate is not enough because it limits each request on its own.

Source: upstream source

Directives

limit_traffic_rate #

syntax: limit_traffic_rate 1 arg;  ·  context: http, server, location

Selects the zone and rate used for the response. Rate units: k (kilobytes/sec), m (megabytes/sec), or plain bytes/sec. The rate must be greater than zero. The zone and rate are selected together. The rate is a fixed configuration value. off disables this module; native nginx limit_rate remains in effect.

limit_traffic_rate_zone #

syntax: limit_traffic_rate_zone 2 args;  ·  context: http

Defines a shared memory zone that tracks download rates keyed by a given variable for later rate-limiting enforcement.

Example

http {
    limit_traffic_rate_zone $binary_remote_addr zone=normal:32m;
    limit_traffic_rate_zone $binary_remote_addr zone=slow:32m;

    expr is_slow str_starts_with $uri /download/slow/;
    limit_traffic_rate zone=normal rate=500k;

    server {
        location /download/ {
            when is_slow {
                limit_traffic_rate zone=slow rate=100k;
            }
        }

        location /unlimited/ {
            limit_traffic_rate off;
        }
    }
}

↑ back to index