Does nginx HttpLimitReqModule support per hour/day/week? Does nginx HttpLimitReqModule support per hour/day/week? nginx nginx

Does nginx HttpLimitReqModule support per hour/day/week?


I'm not aware of a function within nginx that would do it. However you could use the auth_request module to hand of all incoming traffic to an upstream web service which inspected the traffic and applied the rate limiting rules.

location / {    auth_request /ratelimiter;    ..    Normal configuration settings}location /ratelimiter {    proxy_pass http://internalratelimitinghost;    # return a HTTP 200 to allow the request    # return anything else to deny it}

nginx auth_request. The module is not included by default so you would need to compile it in.


At some point, I needed the same function to define rate limits per hour, day, week, etc.

I was itchy to build a clone of ngx_http_limit_req_module first, but then just integrated the necessary changes to nginx-mod.

So this works with nginx-mod:

limit_req_zone $binary_remote_addr zone=one:10m rate=1r/h; # 1 request per hourlimit_req_zone $binary_remote_addr zone=one:10m rate=1r/d; # 1 request per daylimit_req_zone $binary_remote_addr zone=one:10m rate=1r/w; # 1 request per weeklimit_req_zone $binary_remote_addr zone=one:10m rate=1r/M; # 1 request per monthlimit_req_zone $binary_remote_addr zone=one:10m rate=1r/Y; # 1 request per year