I am using NGINX as a reverse proxy to an upstream server.
Is there any way that I can limit the number of simultaneous connections NGINX establishes to the upstream server?
The desired behaviour is:
The NGINX documentation alludes to a couple of parameters in the module ngx_http_upstream_module namely max_conns
and queue
. The problem is that these parameters are only available in the commercial version of NGINX.
Is there any other way of achieving this behaviour without resorting to the commercial version of 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.
upstream defines a cluster that you can proxy requests to. It's commonly used for defining either a web server cluster for load balancing, or an app server cluster for routing / load balancing. Save this answer.
NGINX can also buffer any excess requests in a queue and process them promptly. You can enable this behavior in rate-limiting using the burst parameter with the limit_req directive.
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.
For the max_conns parameter docs states that:
Since version 1.5.9 and prior to version 1.11.5, this parameter was available as part of our commercial subscription.
So, now it is available in the free public version.
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