Nginx – Limiting the number of requests over a long period of time

I apologize if the question has already been asked – I googled for a long time and didn’t find anything..

The problem is this:

  1. let’s say the client makes a lot of requests to the server, for example 60 thousand / day;
  2. Nginx config configures a rate limit of 50 requests/second;
  3. Everything is fine, but the client makes 1-4 requests per second for 10-20 hours in a row without stopping, so it falls within the limits.

Task:

  1. Abnormal behavior is when a client makes requests to our server for a VERY long time;
  2. I want nginx to somehow block the IP if the client makes a request for 10 minutes or an hour or two without stopping, no matter how many times per second.

Let’s say you can block an IP through a fail2ban, but I don’t know how to configure Nginx in such a way that it understands that a certain IP has been making requests for… 20 hours in a row and this is not normal)

Help, please, I’ve run out of ideas..

Tried setting the rate limits, but I can’t afford to set it to 1 request per minute, let’s say, and that’s not the problem. The problem is that the client makes a lot of requests throughout the day.

Read more here: Source link