Nginx access speed limit configuration method detailed

  

Just encountered a bug in the network can be re-created, local debugging access to the machine is too fast, configure Nginx successfully reached the speed limit purpose, share it here.

Simple configuration, just 3 lines, open "nginx root directory /conf/nginx.conf" configuration file is modified as follows:

View source code printing help
Code is as follows http{ ……limit_zone one $binary_remote_addr 10m; …… server { location /{ …… limit_conn one 2; limit_rate 40k; } } }

Explanation of the above configuration: limit_zone defines a storage session state for each IP Container. This example defines a 10m container named one, which will be used in the later limit_conn. Limit_conn specifies that each visitor can only create two links, and limit_rate limits the speed of each link to no more than 40K. Therefore, the above configuration limits the maximum speed limit for users accessing this site to 80K.

Property Description limit_zone

Syntax: limit_zone zone_name $variable memory_max_size

Scope: http

limit_conn

Syntax: limit_conn zone_name Allowed Number of links established per client

Scope: http, server, location

limit_rate

Syntax: limit_rate Maximum rate per link

Scope: http, server, location

Case 1: The download resource is placed in the http://domain/download/path. The download speed limit is 100K for each visitor, and only one link can be linked at the same time. Download link.

View source code print help
Code is as follows http{ server { location /download/{ …… limit_conn one 1; limit_rate 100k; } }

} Case 2: Each visitor visits the site The maximum speed is no more than 100K, and 5 links can be established.

View source code printing help
Code is as follows http{ server { location /download/{ …… limit_conn one 5; limit_rate 20k; } } }

Since linit_rate is for each link Speed, the above example has 5 links, to ensure that the total speed does not exceed 100K, each link does not exceed 20K

Copyright © Windows knowledge All Rights Reserved