Home>Article>Operation and Maintenance> What are the ways to implement current limiting in nginx?

What are the ways to implement current limiting in nginx?

王林
王林 forward
2020-06-22 17:08:08 3479browse

What are the ways to implement current limiting in nginx?

By looking at the official nginx documentation, we can know that there are three nginx current limiting methods, namely:

(Recommended tutorial:nginx tutorial)

1, limit_conn_zone

2, limit_req_zone

3, ngx_http_upstream_module

Here is a brief introduction to the above three methods:

1. limit_conn_zone

nginx configuration

http{ limit_conn_zone $binary_remote_addr zone=one:10m; server { ...... limit_conn one 10; ...... } }

Among them, "limit_conn one 10" can be placed in the server layer to be effective for the entire server, or it can be placed in the location only for a single location is valid.
This configuration indicates that the number of concurrent connections for the client can only be 10.

2. limit_req_zone

nginx configuration

http{ limit_req_zone $binary_remote_addr zone=req_one:10m rate=1r/s; server { ...... limit_req zone=req_one burst=120; ...... } }

"limit_req zone=req_one burst=120" can be placed in the server layer pair It is valid for the entire server, or it can be placed in a location and is only valid for a single location.

rate=1r/s means that each address can only be requested once per second, which means that the token bucket burst=120 has a total of 120 tokens, and only new ones are added every second. After 1 token and 120 tokens are issued, additional requests will return 503.

3. ngx_http_upstream_module

nginx configuration

upstream xxxx{ server 127.0.0.1:8080 max_conns=10; server 127.0.0.1:8081 max_conns=10; }

The above is the detailed content of What are the ways to implement current limiting in nginx?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete