Nginx limit requests globally

user3393046 asked:

I have searched the whole website and google and couldnt find what i am looking for.

Currently i know that we can limit requests / ip with for example

limit_req_zone $binary_remote_addr zone=one:30m rate=20r/s;

and we can use in any location we want like

limit_req zone=one burst=10 nodelay;

My question is. How do i limit requests globally for all ips at the same time? In short, i have a PHP-FPM location, that i want no matter what, all requests to not exceed 200 requests / second.

I guess we have to replace the $binary_remote_addr, but i have no idea with what.

My answer:


Make something up, that is unique and won’t match anything else.

That field in limit_req_zone is just a key, and it’s used as a lookup in the specified zone. If you have a static key, then all the lookups will match the same, and the limit for that zone will be effectively global.

For example:

limit_req_zone global zone=my_php_location_to_limit:1k rate=200/s;

Here, global has no semantic meaning. It’s just a random bit of text. It could be anything or something or nothing.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.