Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NGINX: Limit the number of connections to an upstream server

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:

  • NGINX keeps a maximum of n connections to the upstream
  • If clients make (n + m) connections then m connections should be queued and submitted to the upstream server as soon as an established connection becomes free.

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?

like image 987
Casper Avatar asked Jun 17 '16 10:06

Casper


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 does upstream work NGINX?

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.

Can NGINX Do Rate limiting?

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.

How many API calls 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

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.

like image 175
olegabr Avatar answered Nov 14 '22 21:11

olegabr