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

What are the ways to implement current limiting in nginx?

王林
Release: 2020-06-22 17:08:08
forward
3664 people have browsed it

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; 
  ...... 
 } 
}
Copy after login

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; 
  ...... 
 } 
}
Copy after login

"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; 
 
}
Copy after login

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template