I would like to apply rate limiting based on 3 different criteria.
- CDN should have rate limit of 100 r/s (identified by $http_host)
- Whitelisted bots should have a rate limit of 15 r/s (identified by
$http_user_agent) - 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;