9

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.

1 Answer 1

13

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.

2
  • 1
    Ah! I'm so dumb. Now i noticed. You made also the zone 1k, because since the key is static it wont exceed 1k? Nov 26, 2016 at 0:08
  • 1
    It'll only really be a few bytes. So why waste memory? Nov 26, 2016 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.