Nginx: limit the number of concurrent connections per IP address

We use nginx with the application server as a backend.

We need to limit the number of concurrent connections for each IP address. For this purpose, we used the limit_conn nginx directive. But in all cases this does not work. If the user generates many connections from one IP address and quickly closes them, then nginx sends this request to the backend, but since the client connection is already closed, this connection is not considered to limit_conn .

Is it possible to limit the number of concurrent connections for each IP server on a server with nginx?

+6
source share
2 answers

You might want to install

 proxy_ignore_client_abort off; 

Determines whether the connection to the proxy server should be closed if the client closes the connection without waiting for a response.

from the documentation

Another suggestion is to use limit_req to limit the request speed.

+3
source

I am afraid that this tool is not available for nginx out of the box. According to Nginx Frequently Asked Questions

Many users asked Nginx to implement the load balancer function to limit the number of requests for the backend (usually by one). Although such support is planned, it is worth mentioning that the demand since this function is rooted in improper behavior by the application is proxied

I saw several third-party modules for nginx-limit-upstream , but I never tried.

0
source

Source: https://habr.com/ru/post/948932/


All Articles