Limiting protection --nginx limiting module

1. The number of restriction request module --limit_req_zone

  a meaning:. limit_req_zone meant to limit the number of requests per unit time, i.e., rate limiting, the leaky bucket algorithm

  a. Add conf / nginx.conf profile

Copy the code
http {

    ......

    # Limit the number of requests parameters
    limit_req_zone $binary_remote_addr zone=one:10m rate=5r/m;

    ......

    server {

        ......

        location / print producer {

            ......

            # Limit the number of requests
            limit_req zone=one burst=10 nodelay;
            # Custom return code
            limit_req_status 598;

            ......

        }
Copy the code

 

  . B Parameters:

    $ Binary_remote_addr: represent the same client ip to limit the number of requests by the logo remote_addr

    zone = one: 10m: represents a size of generating 10M, the name of one memory area for storing information accessed frequency

    rate = 5r / m: represents allows clients to access the same frequency identification, where the limit is 1 per second, can also have such 1r / s

    zone = one: represents a zone configuration which limits use to do, name corresponding to the above in the limit_req_zone

    burst = 5: represents a size of the buffer 5 is provided when a large number of requests (outbreak) over time, request access frequency exceeds the limit may be placed in the first buffer zone

    nodelay: If, over time the frequency of access and the buffer is full it will also return 503 directly, if not set, all requests will wait queue

    limit_req_status 598: Set refusing to return to the requested value. Can only be set between 400 to 599 (default is 503)

 

 

2. Download speed limit

  a. Add conf / nginx.conf profile

Copy the code
http {

    ......

    server {

        ......

        location /download{

            ......

            Any speed threshold #
            limit_rate_after 10m;
            # Exceeds the threshold limit speed
            limit_rate 10k;

            ......

        }
Copy the code

 

  . B Parameters:

    limit_rate_after 10m: 10m indicates when the size of the rate limitation before

    limit_rate 10k: limit_rate_after at a rear more than 10kb / s speed

 

 

3. Reference article:

  https://www.cnblogs.com/biglittleant/p/8979915.html

  https://my.oschina.net/gaga/blog/495444

Guess you like

Origin www.cnblogs.com/ExMan/p/11795119.html