limit_traffic_rate_zone
The `limit_traffic_rate_zone` directive defines a shared memory zone with limits for controlling the download rate for specific traffic variables.
Description
The limit_traffic_rate_zone directive is used to create a shared memory zone that keeps track of traffic rates for a given variable, typically the client’s IP address or a specific request URI. This directive is crucial for implementing traffic shaping by limiting the overall bandwidth available to clients over a set time frame.
This directive requires three arguments: the rate limit type, a variable that will be monitored (such as $remote_addr to specify IP address or $request_uri for specific URLs), and the size of the memory zone (e.g., 32m). The shared memory zone stores information necessary to calculate the download rate and manage connection limits effectively, allowing NGINX to adjust traffic rates as required to prevent bandwidth over-utilization.
To enforce the limitations, the limit_traffic_rate directive must also be configured within the appropriate context (like server or location). This directive then utilizes the settings established in limit_traffic_rate_zone to manage how much data is sent to a client based on the defined traffic rate.
Config Example
http {
limit_traffic_rate_zone rate $remote_addr 32m;
server {
location /download/ {
limit_traffic_rate rate 20k;
}
}
}Ensure that the memory zone size is large enough to accommodate the expected number of concurrent connections.
Be cautious with the rate parameter defined in the limit_traffic_rate directive to avoid unintended throttling.
Make sure to reload NGINX after making changes to apply the new configurations.