Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can you set an exception for nginx's requests per second limit?

We try to save nginx resources by limiting the number of requests per second:

http {
    limit_req_zone  $binary_remote_addr  zone=gulag:10m  rate=2r/s;

    server
    {
        location / {
         proxy_pass http://0.0.0.0:8181;
         limit_req   zone=gulag  burst=40;
        }
    }
}

However, most employees in our company are also heavy users of our own website. Since everyone in the company appear to come from the same ip address were getting 503 errors because nginx thinks all the traffic is coming from one user. Can we add our ip as an exception to the requests per second limit?

like image 928
Andrew Kloos Avatar asked Sep 17 '25 12:09

Andrew Kloos


1 Answers

Yes, you can. Just a quote from the documentation:

The key is any non-empty value of the specified variable (empty values are not accounted).

So you can achieve your goal by using geo and map modules like this:

geo $limited_net {
    default      1;
    10.1.0.0/16  0;
}

map $limited_net $addr_to_limit {
    0  "";
    1  $binary_remote_addr;
}

limit_req_zone  $addr_to_limit  zone=gulag:10m  rate=2r/s;
like image 194
VBart Avatar answered Sep 20 '25 06:09

VBart