Get the App
SLTechnology News&Howtos  ›  Servers  › 

Nginx limits the number of visits and concurrency

Shulou Source: shulou.com Published: 2022-06-02 17:32:54 09月22日 Update

Nginx limit access rate and maximum number of concurrent connections module-limit (prevent DDOS)

Http:

# # zone=one or allips means to set a storage named "one" or "allips" with a size of 10 megabytes

# # rate=2r/s allows no more than 2 requests per second

Limit_conn_log_level error

Limit_conn_status 503

Limit_conn_zone $binary_remote_addr zone=one:10m

Limit_conn_zone $server_name zone=perserver:10m

Limit_req_zone $binary_remote_addr zone=allips:100m rate=2r/s

Server:

# # burst=5 means that the maximum number of delayed requests is not greater than 5. If too many requests are delayed and it is not necessary to use the nodelay parameter, the server will return the 503 status code immediately.

Limit_conn one 100; # # indicates the maximum number of concurrent connections

Limit_conn perserver 1000

Limit_req zone=allips burst=5 nodelay

Parameter explanation:

$binary_remote_addr restricts the same client ip address

$server_name limits the maximum number of concurrency of the same server

Limit_conn is to limit the number of concurrent connections

Limit_rate is to limit download speed.

Tags: Limit maximum parameter delay address size byte customer client quantity server module state excess speed rate storage service interpretation number of times Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Redmi Shulou Tech Info Apple Xiaomi