Ratelimit CIDR/IP ranges with NGINX

Here is simple way to ratelimit while IP ranges with Nginx.

In HTTP block, create map with limit zones

geo $is_limited {
   default 0;
   123.123.0.0/10 1;
}

map $is_limited $limit_key {
   0 "";
   1 $binary_remote_addr;
}

limit_req_zone $limit_key zone=req_limit_zone:10m rate=3r/s;
limit_req_status 429;

Now add this to your server block to limit requests:

...
location / {
   limit_req zone=req_limit_zone burst=10 nodelay;
...

Got Something To Say:

Your email address will not be published. Required fields are marked *

*

I accept the Privacy Policy

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2026 geegkytuts.net
Hosted by SIEL


About author