Nginx: Limit number of simultaneous connections per IP to backend

nginx

Solution

You may want to set

proxy_ignore_client_abort off;

Determines should the connection with a proxied server be closed if a client closes a connection without waiting for a response.

from the documentation

Another suggestion is to use `limit_req` to limit the request rate.

Problem

We use nginx with an application server as a backend. We need to limit number of simultaneous connections per IP to backend. We used `limit_conn` nginx directive for this purpose. But it doesn't work well in all cases. If user generates a lot of connections from one IP and quickly closes them, then nginx passes this request to a backend, but because client connection is already closed, this connection is not count in `limit_conn`. Is it possible to limit number of simultaneous connections per IP to backend server with nginx?

Original source