Configure multiple rate limits and override default rate limit
July 18, 2023 05:10AM
Hi,

I am currently trying to configure a different rate limit for a specific IP and have tried to configure Nginx around this, however with my configuration below, I keep hitting the default rate limit unless I remove burst from the override zone. How do I configure multiple rate limits with the idea of one of the rates overriding the "default" rate by a specific IP address.

Nginx 1.24 Sample config:


geo $remote_addr $client_rate_limit {
default 1;
123.123.123.123 0;
}

map $client_rate_limit $override_client_rate_limit {
1 "";
0 "$remote_addr";
}

limit_req_zone $uri zone=another_api_rate_limit:64m rate=100r/s;
limit_req_zone $override_client_rate_limit zone=override_web_api_client_rate_limit:64m rate=50r/s;
limit_req_zone $remote_addr zone=client_rate_limit:64m rate=25r/s;


server {

...

limit_req zone=override_web_api_client_rate_limit burst=200;
limit_req zone=another_api_rate_limit burst=500;
limit_req zone=client_rate_limit burst=200;
limit_req_status 429;

location ~* ^/test {
...
}

}

Is there some precedence on what gets applied with multiple rate limits?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 315
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready