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?
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.
Nginx is event based and by default runs as 1 process supporting max 512 concurrent 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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With