Nginx bandwidth limiting configuration example

  • 2020-05-09 19:52:32
  • OfStack

Example 1:


http {
   limit_rate 25k;                              # Speed limit per connection
   limit_zone to_vhost $server_name 1m;         # Total bandwidth limit per domain name
   limit_conn to_vhost 30;                      # How many threads can be opened per connection
}

Example 2:

When using Nginx for a download service, you might want to limit the download speed. Nginx can do this:
Start by adding a single item to the http{} configuration:
limit_zone one $10 m binary_remote_addr; Then in the configuration of server{} add:


location / {
limit_conn one 1; Limit the thread
limit_rate 100k; Speed limits
}

Means the speed limit of 100K only one thread per client is allowed
 
The client end speed =rate * conn, which makes it perfect for bandwidth limiting Settings.
 
Detailed official rules:
http://wiki.nginx.org/NginxChsHttpLimit_zoneModule

Example 3:

Add http{} in nginx.conf


limit_zone one $binary_remote_addr 10m;

And then write it in the virtual machine


location / {
  limit_conn one 1; thread
  limit_rate 100k; speed
}
   
Means the speed limit of 100K only allows one thread per client

The client final speed =rate * conn, which makes it perfectly possible to set bandwidth limits.


Related articles: