skip to Main Content

I successfully implemented rate limiting in the nginx-configuration with limit_req_zone and limit_req as documented on the nginx blog

The rate limiting settings is configured pretty strict. So I sometimes run into the rate-limit if I have to do some admin tasks.

So my question is:
Is it possible to somehow reset this rate limiting without restarting the nginx-process?

Restarting the nginx-process works, but I did not find another solution in the docs or online.

2

Answers


  1. I believe it’s really better for you to find a url location pattern, for your admin area. in that case you can define another rate limit with a much higher limit and set it for that specific url. something like this:

    limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;
    limit_req_zone $binary_remote_addr zone=adminlimit:10m rate=30r/s;
    
    server {
        
        location ~* /admin/* {
            limit_req zone=adminlimit;
            
            ...
        }
    }
    
    Login or Signup to reply.
  2. To achieve your goal, it would not help much to reset the whole memory_zone, wouldn‘t it? However for NGINX Plus it is possible to reset a whole memory zone using the NGINX Plus API.

    http://nginx.org/en/docs/http/ngx_http_api_module.html#http_limit_reqs_http_limit_req_zone_name

    DELETE – Reset statistics for an HTTP limit_req zone
    Resets the requests limiting statistics.

    The NGINX API module is just available with the commercial subscription and does not come along with NGINX OSS.

    If you would need to reset the rate limit per rate_key or user / client, I would highly recommend to define a header / cookie /remote adders for such tasks / clients that will exclude such clients / tasks from the rate limiting.

    For example. If your are logged in and send the cookie you can validate the cookie and exclude admins from the rate limit for all URLs. Same for some known remote addresses. This is the common way to achieve such tasks and is also mentioned in the blog you have just found.

    Happy to learn more about the use case if this does not apply to your requirements.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search