HTTP {
Limit_conn_zone $ binary_remote_addr zone = Conn: 10 m;
Server {
Location /{
Limit_conn conn 2;
}
}
}
Limit_conn_zone is used in the HTTP segment.
Limit_conn can be used in HTTP,Server, Location section.
Use the new nginx syntax limit_conn_zone to replace limit_conn
Replace limit_conn with limit_conn_zone in the nginx. conf file in the conf folder. Used in HTTP
Example:
Limit_conn_zone $ binary_remote_addr zone = perip: 10 m; # The container uses a total of 10 m memory for IP Address Transmission overhead.
Replace the original limit_conn one with limit_conn perip. Used on server
Example:
Limit_conn perip 10; # Each IP uses 10 connections.
Explanation
Command name: limit_zone (Use the new nginx syntax limit_conn_zone to replace limit_conn)
Function: this command is used to define a zone, and the zome will be used to store the session status. The number of sessions that can be stored is determined by the delivered variable and the size of memory_max_size.
For example:
Limit_zone one $ binary_remote_addr10m; |
The IP address of the client is used as the session. Note that $ binary_remote_addr is used instead of $ remote_addr. This is because the length of $ remote_addr is 7 to 15 bytes, the length of the session information is 32 or 64 bytes. The length of $ binary_remote_addr is 4 bytes, and the length of the session information is 32 bytes. When a zone of 1 MB is set, if $ binary_remote_addr is used, the zone will store 32000 sessions.
Syntax: limit_zone zone_name $ variable memory_max_size
Default Value: No
Environment: HTTP
Command name: limit_conn
Function: this command is used to set the maximum number of concurrent connections for a session. If the number of concurrent requests exceeds this limit, "Service unavailable" (503) is displayed ).
For example:
[HTML]View plaincopy
Limit_zone one $ binary_remote_addr 10 m;
Server {
Location/download /{
Limit_conn one 1;
}
Nginx limits IP concurrency