I want to control the transfer volume with nginx's ngx_http_limit_req_module.

Asked 2 years ago, Updated 2 years ago, 38 views

I would like to use nginx's ngx_http_limit_req_module to control the amount of transfer.

https://gist.github.com/miurahr/fe953d47f4148e15e517

http{
    limit_req_zone$binary_remote_addr zone=tile_req:20m rate=16r/s;
    ...
server{
    ...
    location / {
         limit_req zone = tile_req burst = 45;
} 

The token bucket algorithm allows flow control in this way, and nodelay makes it work like a leaky bucket algorithm.

Now, is it possible to control both sides in a way that is good?

What we want to do is access from the same IP address.

1. I want to control the flow rate according to the average transfer amount that burst is allowed.
2. I would like to return a dedicated error page with an http429 response code to clients that continue to use the upper limit for a long time (for example, 10 minutes).

It's about satisfying both at the same time.(1)Single can be achieved with the above configuration. (2) Single can be achieved with nodelay per minute and per hour.

Both can be accomplished in a single way, but is it possible to achieve both simultaneously?

How about doing this?

http{
    limit_req_zone$binary_remote_addr zone=throttle:20m rate=16r/s;
    limit_req_zone$binary_remote_addr zone=abuse —20m rate=960r/m;
    ...
server{
    ...
    location / {
         limit_req zone = throttle burst = 45;
         limit_req zone =abuse modelay;
    }

nginx

2022-09-29 20:28

1 Answers

I feel that it will be difficult as requested.
Wouldn't this be an alternative?

  • Use limit_rate and limit_rate_after to limit the transfer to the extreme
  • Turn off after a certain period of time with timeout


2022-09-29 20:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.