Nginx limits IP concurrency

Source: Internet
Author: User

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

  1. Limit_zone one $ binary_remote_addr 10 m;

  2. Server {

  3. Location/download /{

  4. Limit_conn one 1;

  5. }





Nginx limits IP concurrency

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.