Monday, June 22, 2015

Nginx limit requests globally



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.


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.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...