Nginx limits ip concurrency and speed

Source: Internet
Author: User
Nginx limits the number of concurrent ip addresses, that is, limits the number of simultaneous connections from the same ip address to the server. add the limit_zone variable to use vi/usr/local/nginx/conf/nginx only in http. conflimit_zoneone $ remote_addr10m; 2. you can add the limit_conn variable in http, server, and loca.

Nginx limits the number of concurrent ip addresses, that is, limits the number of simultaneous connections from the same ip address to the server.

1. add limit_zone
This variable can only be used in http
Vi/usr/local/nginx/conf/nginx. conf
Limit_zone one $ remote_addr 10 m;

2. add limit_conn
This variable can be used in http, server, and location.
I only restrict one site, so add it to the server
Vi/usr/local/nginx/conf/host/gaojinbo.com. conf
Limit_conn one 10;

3. restart nginx
Killall-HUP nginx

Nginx speed limit module
Refer:

About limit_zone: http://wiki.nginx.org/NginxHttpLimitZoneModule
About limit_rate and limit_conn: http://wiki.nginx.org/NginxHttpCoreModule
Nginx can use HTTPLimitZoneModule and HTTPCoreModule to speed up directories.

Http {
Limit_zone one $ binary_remote_addr 10 m;
Server {
Location/download /{
Limit_conn one 1;
Limit_rate 300 k;
}
}
}

Limit_zone is a container that defines the session state for each IP address. In this example, a 10 m container is defined. according To 32 bytes/session, 320000 sessions can be processed.

Limit_conn one 1;
Each IP address can only initiate one concurrent connection.

Limit_rate 300 k;
The speed limit for each connection is 300 k. Note that the speed limit for the connection is here, not for the IP address. If an IP allows two concurrent connections, the IP address is limited to limit_rate × 2.

Related Article

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.