limit-traffic-rate: NGINX Limiting rate by given variables
Debian/Ubuntu installation
These docs apply to the APT package nginx-module-limit-traffic-rate provided by the GetPageSpeed Extras repository.
- Configure the APT repository as described in APT repository setup.
- Install the module:
sudo apt-get update
sudo apt-get install nginx-module-limit-traffic-rate
Show suites and architectures
| Distro | Suite | Component | Architectures |
|----------|-------------------|-------------|-----------------|
| debian | bookworm | main | amd64, arm64 |
| debian | bookworm-mainline | main | amd64, arm64 |
| debian | trixie | main | amd64, arm64 |
| debian | trixie-mainline | main | amd64, arm64 |
| ubuntu | focal | main | amd64, arm64 |
| ubuntu | focal-mainline | main | amd64, arm64 |
| ubuntu | jammy | main | amd64, arm64 |
| ubuntu | jammy-mainline | main | amd64, arm64 |
| ubuntu | noble | main | amd64, arm64 |
| ubuntu | noble-mainline | main | amd64, arm64 |
Notes
Nginx directive limit_rate could limit connection's speed, and limit_conn could limit connection number by given variable. If the client is a browser, it only open one connection to the server. The speed will be limited to limit_rate, unless the client is a multi-thread download tool.
ngx_http_limit_traffic_ratefilter_module provides a method to limit the total download rate by client IP or download URL, even there are several connections. The limit condition could be defined by the following directive.
To install, compile nginx with this ./configure option:
--add-module=path/to/this/directory
The limit_traffic_rate module need to use a share memory pool.
Directive syntax is same to limit_zone
http {
#limit_traffic_rate_zone rate $request_uri 32m;
limit_traffic_rate_zone rate $remote_addr 32m;
server {
location /download/ {
limit_traffic_rate rate 20k;
}
}
}