Joyce Babu
January 09, 2015 08:50AM
I would like to apply rate limiting based on 3 different criteria.

1. CDN should have rate limit of 100 r/s (identified by $http_host)
2. Whitelisted bots should have a rate limit of 15 r/s (identified by
$http_user_agent)
3. All other users should have a rate limit of 5 r/s

The rules should be applied in the above order of preference. If a rule
matches two criteria, the earlier one should get applied. How can I ensure
this?

I have tried the following config, but it is always rate limited to 5 r/s,
irrespective of the order of the limit_req entries.

map $http_host $limit_cdn {
default '';
"cdn-cname.mydomain.com" $binary_remote_addr;
}
map $http_user_agent $limit_bot {
default '';
~*(google|bing) $binary_remote_addr;
}

limit_req_zone $limit_cdn zone=limit_cdn:1m rate=100r/s;
limit_req_zone $limit_bot zone=limit_bot:1m rate=15r/s;
limit_req_zone $binary_remote_addr zone=limit_all:10m rate=5r/s;

limit_req zone=limit_all burst=12;
limit_req zone=limit_bot burst=50 nodelay;
limit_req zone=limit_cdn burst=200 nodelay;
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Multiple matching limit_req

Joyce Babu January 09, 2015 08:50AM

Re: Multiple matching limit_req

Francis Daly January 09, 2015 02:18PM

Re: Multiple matching limit_req

Joyce Babu January 10, 2015 12:52AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 187
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