Nginx limit the number of IP concurrency and download speed of the method _nginx

Source: Internet
Author: User
Tags nginx server

Make some general settings on the Nginx server to limit the number of concurrent and session space.

Nginx limit the number of IP concurrency, but also to limit the number of simultaneous connections to the same IP server

1, add Limit_zone

This variable can only be used on HTTP

code example:

Copy Code code as follows:

Vi/usr/local/nginx/conf/nginx.conf
Limit_zone one $remote _addr 10m;

2, add Limit_conn

This variable can be used in HTTP, server, location
Limit only one site, so add it to the server

Copy Code code as follows:

Vi/usr/local/nginx/conf/vhost/303i.com.conf
Limit_conn one 10;

3, restart Nginx

Copy Code code as follows:
Service Nginx Restart

Nginx Speed Limit Module
Reference:
About Limit_zone:http://wiki.nginx.org/nginxhttplimitzonemodule
About Limit_rate and Limit_conn:http://wiki.nginx.org/nginxhttpcoremodule

Nginx can speed up the directory by Httplimitzonemodule and httpcoremodule two components.

Copy Code code as follows:

HTTP {
Limit_zone one $binary _remote_addr 10m;
server {
location/download/{
Limit_conn one 1;
Limit_rate 300k;
}
}
}

Limit_zone is a container that defines a storage session state for each IP.

This example defines a 10m container that, according to 32bytes/session, can handle 320,000 sessions.

Copy Code code as follows:

Limit_conn one 1;

Restrict each IP to initiate only one concurrent connection.

Copy Code code as follows:

Limit_rate 300k;

Speed limit 300k for each connection.

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.

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.