Using Nginx to limit the number of concurrent connections for a single IP can reduce some acquisition programs or DDoS attacks.
LNMP the Nginx configuration has been added to some of the code, but is commented out, you can edit the/usr/local/nginx/conf/nginx.conf file
1.1.8 above version of Nginx settings:
Find:copy content to clipboardCode:
#limit_conn_zone $binary_remote_addr zone=perip:10m;
, remove the previous #, without this line, addcopy content to clipboardCode:
limit_conn_zone $binary_remote_addr zone=perip:10m;
Add the server segment in the virtual host configuration where you want to set the limit number of connectionscopy content to clipboardCode:
limit_conn perip 10;
10 is the maximum number of concurrent connections for a single IP.copy content to clipboardCode:
limit_rate 100k;
The limit_rate is limited to 100kb/seconds.
Limit each connection speed of 100K, this limit is for a single thread, for example, I use IE download is 100K, when using Thunderbolt it will occupy 2 threads, so thunder download speed is 200K, if the number of concurrent single IP set to 10, then multi-threaded download speed can reach 100kx10.
Finally/USR/LOCAL/NGINX/SBIN/NGINX-T test the configuration for errors, such as no error execution:
/usr/local/nginx/sbin/nginx-s Reload overload configuration makes it effective
####################################################
The following are the settings for the previous Nginx version:
Find:copy content to clipboardCode:
#limit_zone oneip $binary_remote_addr 10m;
To remove the previous #, without this line, words Pluscopy content to clipboardCode:
limit_zone oneip $binary_remote_addr 10m;
, and then add it in the server segment of the virtual host configurationcopy content to clipboardCode:
limit_conn oneip 20;
The number at the back of the Limit_conn statement is the maximum number of concurrent connections for a single IP.
If the non-LNMP installation is also very simple, add in nginx.confcopy content to clipboardCode:
limit_zone oneip $binary_remote_addr 10m;
limit_conn oneip 20;
Of course, Limit_conn ONEIP 20; Statements can also be added to a server segment to make this restriction only for a virtual host.
Limit the number of concurrent numbers directly in the server segment add Limit_rate 100k below this line;
Limit each connection speed of 100K, this limit is for a single thread, for example, I use IE download is 100K, when using Thunderbolt it will occupy 2 threads, so thunder download speed is 200K, if the number of concurrent single IP set to 20, then multi-threaded download speed can reach 100kx20.
Finally, the nginx can be restarted.
Nginx limits the number of concurrent connections for a single IP and for each connection speed (speed limit)