Nginx Limit number of IP links, nginx How to limit the number of concurrent, the same 1 ip,nginx how to limit the flow/limit bandwidth?

Source: Internet
Author: User

Nginx limits the number of IP concurrency, which is also the limit of the same IP to connect to the server at the same time. How can Nginx limit the number of connections to the same IP, limit the number of concurrent, limit traffic/limit bandwidth? By using the Nginx module below, we can set the number of concurrent links to exceed our settings and will return 503 errors to each other. This can be very effective in preventing CC attacks. In conjunction with the Iptables firewall, basically a CC attack can be ignored. Nginx Limit number of IP links, nginx How to limit the number of concurrent, the same 1 ip,nginx how to limit the flow/limit bandwidth? Please see below:

Nginx Limit the number of IP concurrency, nginx limit the number of IP links Example reference:

Limit_zone Ctohome_zone $binary _remote_addr 20m;
Limit_req_zone $binary _remote_addr zone=ctohome_req_zone:20m rate=2r/s;

server {
Listen *:80;
server_name www.ctohome.com. ctohome.com;

Location/{
Proxy_pass http://1.2.3.4;
Include Vhosts/conf.proxy_cache;
}

Location ~. *\. (php|jsp|cgi|phtml|asp|aspx)? $ {
Limit_conn Ctohome_zone 2;
Limit_req Zone=ctohome_req_zone burst=3;
Proxy_pass http://4.3.2.1;
Include Vhosts/conf.proxy_no_cache;
}
}



How Nginx restricts the number of connections to the same IP, limiting the number of concurrent

1. Add Limit_zone
This variable can only be used in HTTP
Vi/usr/local/nginx/conf/nginx.conf
Limit_zone Ctohome_zone $remote _addr 10m;

2. Add Limit_conn
This variable can be used in HTTP, server, location
I only limit a site, so add to the server inside
Vi/usr/local/nginx/conf/host/www.ctohome.com.conf
Limit_conn Ctohome_zone 2;

3. Restart Nginx
Killall-hup Nginx

nginx limit traffic/limit bandwidth?

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 two components to limit the speed of a directory.

HTTP {
Limit_zone one $binary _remote_addr 10m;
server {
location/download/{
Limit_conn Ctohome_zone 2;

limit_rate 300k;
}
}
}

Limit_zone is a container that stores the session state for each IP. This example defines a 10m container that can handle 320,000 sessions according to 32bytes/session.

Limit_conn Ctohome_zone 2;
Limit the 2 concurrent connections that can be initiated per IP.

Limit_rate 300k;
The speed limit for each connection is 300k. Note that this is the speed limit for the connection, not the IP speed limit. If an IP allows two concurrent connections, then this IP is the speed limit limit_ratex2.
Ngx_http_limit_zone_module

Nginx Limit number of IP links, nginx How to limit the number of concurrent, the same 1 ip,nginx how to limit the flow/limit bandwidth?

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.