Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx: Limit number of simultaneous connections per IP to backend

Tags:

nginx

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?

like image 532
Anton Avatar asked Jul 08 '13 10:07

Anton


People also ask

How do I limit NGINX connections?

To limit connections, use the limint_conn directive to set the memory zone to be used and the maximum number of allowed connections as shown in the following configuration snippet. This directive is valid within the HTTP, server, and location contexts. Save the file and close it.

How many concurrent connections can NGINX handle?

Nginx is event based and by default runs as 1 process supporting max 512 concurrent connections.

How do you limit the maximum number of connections?

To set a limit on the number of users simultaneously accessing the instance, we can use "Maximum number of concurrent connections" property in SQL Server. The value for this property can be set via SQL Server Management Studio as well as via a T-SQL statement.

How many RPS can NGINX handle?

The configuration allows bursts of up to 12 requests, the first 8 of which are processed without delay. A delay is added after 8 excessive requests to enforce the 5 r/s limit. After 12 excessive requests, any further requests are rejected.


1 Answers

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.

like image 170
Alexander Azarov Avatar answered Oct 14 '22 02:10

Alexander Azarov