With Nginx to build a station students, often limited speed demand. The development of testing phase in the local speed limit simulation of the environment, convenient debugging. The operation will limit the speed of the attachment, limit the speed of each user's access, limit the link speed of each IP and other requirements.
Just encountered a bug in the network is very card in the case to reproduce, local debugging access to the machine too fast, configuration nginx success to achieve speed limit purposes, here to share out.
Simple configuration, only 3 lines, open the "Nginx root/conf/nginx.conf" configuration file modified as follows:
http{...
Limit_zone one $binary _remote_addr 10m;
..... server {
location/{
...
.. Limit_conn one 2;
Limit_rate 40k;
}
}
The above configuration explanation: Limit_zone defines a container that stores session state for each IP. This example defines a container of 10m size named one, which is used in later limit_conn. LIMIT_CONN specifies that each visitor can only establish two links, limit_rate limit the speed of each link to no more than 40K. Therefore, the above configuration restricts user access to this site with a total speed limit of 80K.
Attribute Description Limit_zone
Grammar:
Copy Code code as follows:
Limit_zone zone_name $variable memory_max_size
Scope: http
Limit_conn
Grammar:
Copy Code code as follows:
Limit_conn Zone_name allow each client to establish the number of links
Scopes: HTTP, server, location
Limit_rate
Grammar:
Copy Code code as follows:
Limit_rate the maximum rate per link
Scopes: HTTP, server, location
Case Case 1: Download resources are placed under the http://domain/download/path, download speed limit of 100K for each visitor, and can only link 1 download links at the same time.
http{
Server {
location/download/{
...
.. Limit_conn one 1;
Limit_rate 100k;
}
}
Case 2: The maximum speed per visitor to the site is no more than 100K, and 5 links can be established.
http{
Server {
location/download/{
...
.. Limit_conn one 5;
Limit_rate 20k;
}
}
Since linit_rate is a speed limit for each link, the above example has 5 links to ensure that the total speed does not exceed 100K each link does not exceed 20K