Multiple matching limit_req

Joyce Babu joyce at
Fri Jan 9 13:48:37 UTC 2015

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
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

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 '';
    "" $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;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list