Nginx server's basic configuration method for data transmission speed limit _nginx

Source: Internet
Author: User
Tags nginx server

Attention:
The syntax of the version after Nginx 1.1.8 is changed to Limit_conn_zone $binary _remote_addr zone=name:10m;
Name is zone. Please see here http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html

Limit number of connections:
To limit connections, you must first have a container to count the connections, and add the following code to the HTTP segment:
"Zone=" Give it a name, can be casually called, the name should be consistent with the following limit_conn
$binary _REMOTE_ADDR = Store The address of the client with binary, 1m can store 32,000 concurrent sessions

... Dispense with N word

HTTP
{
limit_conn_zone $binary _remote_addr zone=addr:10m;

Next you need to speed limits for different locations (location segments) of the server, such as limiting the number of concurrent connections per IP to 1,

Server
{
listen;
server_name 192.168.11.128;
Index index.html index.htm index.php;
Limit_conn addr 1; The #是限制每个IP只能发起1个连接 (addr to correspond to Limit_conn_zone variables)
limit_rate 100k; #限速为 100kb/second
root html;

Note:
Limit_rate 100k; is for each connection speed limit 100k. This is the connection speed limit, not the IP speed limit! If an IP allows two concurrent connections, then this IP is the speed limit limit_rate * 2


using the Nginx-limit-traffic-rate-module module
Project Address: Https://github.com/bigplum/Nginx-limit-traffic-rate-module
The instruction Limit_conn under the Ngx_http_limit_conn_module module specifies the maximum number of simultaneous connections for each given key value, limit_rate the rate limit for each connection. The unit of the parameter rate is bytes/sec, and setting to 0 will turn off the speed limit. By connection speed limit rather than by IP, so if a client has two connections open at the same time, the overall rate of the client is twice times the value of this instruction setting. If it is a multi-threaded download, limit_rate does not limit the overall speed.
The Limit_traffic_rate module provides a way to limit the total download speed through client IP or download URLs, even if there are multiple connections.
The restriction method looks like this:

HTTP {
    #limit_traffic_rate_zone  rate $request _uri 32m;
    Limit_traffic_rate_zone  rate $remote _addr 32m;
 
    server {
      location/download/{
        limit_traffic_rate rate 20k;
      }
    }
  }

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.