Nginx limits the number of concurrent connections for a single IP and for each connection speed (speed limit)

Source: Internet
Author: User

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)

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.