Score:0

How to limit Nginx to max 50 request per second independent from IP

in flag

I'm looking for a way to limit Nginx for location to a number of requests per second independent of the origin IP. From my understanding the rate limiting feature is IP sensitive which cannot be turned off.

What would be the right approach here?

jp flag
Does this answer your question? [Nginx limit requests globally](https://serverfault.com/questions/817164/nginx-limit-requests-globally)
frlan avatar
in flag
From my understanding all these options are by IP. So it works if you have e.g. 10r/m from one IP, but what you having request from a /8 or even /0? Am I just missunderstanding the documentation maybe?
ie flag
All those options aren't by IP. The answer here uses a static word (global) to bucket the requests, so all requests will go in the same bucket and be limited independent of IP: https://serverfault.com/a/817165/362828 This part in the question is what makes it by IP: `$binary_remote_addr`. But that key can be set to anything (e.g. you could limit based on a cookie or the request url).
Score:0
ie flag

Like so

limit_req_zone global zone=global_limit:1k rate=50/s;

The global part is the key Nginx uses to bucket requests. By setting it to a static string (could be anything), rather than a variable, all requests will go into the same bucket.

To limit by IP, you would set it to $binary_remote_addr. You can rate limit on just about anything (see https://www.nginx.com/blog/dynamic-bandwidth-limits-nginx-plus-key-value-store/#Complete-Sample-NGINX-Configuratio for a complex example).

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.