# Nginx as reverse proxy scalability

**URL:** <https://www.ruby-forum.com/t/nginx-as-reverse-proxy-scalability/244601>\
**Category:** NGINX\
**Created:** [May 10, 2016, 12:27pm UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-scalability/244601 "2016-05-10T12:27:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [May 10, 2016, 12:27pm UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-scalability/244601/1 "2016-05-10T12:27:32Z")

</div>

Hello,

I’m currently working on nginx limits as a reverse proxy on a Debian  
box.  
My current setup is a nginx configured as a http/https web server (for  
static content) and a reverse proxy for node.js processes on the same  
server and in future on other Debian boxes.  
I was unable to see (while reading the documentation) real hard  
limitations for nginx in this setup excepting ephemeral ports  
exhaustion.  
It may be a concern as Node.js applications usually open a websocket  
that is connected as long as a user stays connected to the application.  
If I understood everything correctly it means that nginx in this setup  
will not be able to manage more than about 64k clients connections.  
Am I right ? What can be done if I would like to go over this 64k limit  
? Could you please suggest a solution ?

–

Best regards,  
Artur.

---

<div class="post-metadata">

**Author:** ![Artur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@Artur](https://www.ruby-forum.com/u/Artur)\
**Post date:** [May 10, 2016, 5:04pm UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-scalability/244601/2 "2016-05-10T17:04:26Z")

</div>

Hello!

On Tue, May 10, 2016 at 12:26:59PM +0200, Artur wrote:

> Am I right ? What can be done if I would like to go over this 64k limit  
> ? Could you please suggest a solution ?

As long as you are using TCP/IP and have only one backend (ip +  
port), and only one local address on nginx side, then you are  
limited by the number of local ports nginx can use. Theoretical  
limit is 64k, practical one is usually smaller - on Linux systems  
it depends on net.ipv4.ip\_local\_port\_range.

Most natural solution is to add more backends. Under normal  
conditions you will add more backend servers as your system will  
grow, so you’ll never hit the problem in the first place. If you  
need to handle more than 64k connections to a single backend  
server, consider listening on multiple addresses in your backend  
application (e.g., listening on multiple ports).

Other available solutions are:

- use UNIX domain sockets (this works when you have everything on  
a single host);

- add more local addresses on nginx side and use proxy\_bind to  
balance users between these addresses.

–  
Maxim D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![Artur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@Artur](https://www.ruby-forum.com/u/Artur)\
**Post date:** [May 10, 2016, 5:24pm UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-scalability/244601/3 "2016-05-10T17:24:53Z")

</div>

On 5/10/16 6:04 PM, Maxim D. wrote:

> > It may be a concern as Node.js applications usually open a websocket  
> > it depends on net.ipv4.ip\_local\_port\_range.
> 
> - use UNIX domain sockets (this works when you have everything on  
> a single host);
> 
> - add more local addresses on nginx side and use proxy\_bind to  
> balance users between these addresses.

- 

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

–  
Maxim K.

---

<div class="post-metadata">

**Author:** ![Artur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@Artur](https://www.ruby-forum.com/u/Artur)\
**Post date:** [May 10, 2016, 5:38pm UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-scalability/244601/4 "2016-05-10T17:38:20Z")

</div>

Thanks for your answer.

Le 10/05/2016 ? 17:04, Maxim D. a ?crit :

> As long as you are using TCP/IP and have only one backend (ip +  
> port), and only one local address on nginx side, then you are  
> limited by the number of local ports nginx can use.  
> I currently have nginx running on the same host that my backends.  
> I have 4 of them listening on different ports on 127.0.0.1.  
> In this situation may I expect 4 times 65000 simultaneous connections ?
> 
> - add more local addresses on nginx side and use proxy\_bind to  
> balance users between these addresses.  
> Yes, I’ve seen this, however I didn’t catch how to dynamically assign a  
> value to proxy\_bind from a pool of IP addresses in nginx (not Nginx  
> Plus).

–

Best regards,  
Artur.

---

<div class="post-metadata">

**Author:** ![Artur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@Artur](https://www.ruby-forum.com/u/Artur)\
**Post date:** [May 10, 2016, 5:43pm UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-scalability/244601/5 "2016-05-10T17:43:35Z")

</div>

On Tuesday 10 May 2016 17:37:55 Artur wrote:

> > balance users between these addresses.  
> > Yes, I’ve seen this, however I didn’t catch how to dynamically assign a  
> > value to proxy\_bind from a pool of IP addresses in nginx (not Nginx Plus).

The all proxy\_bind functionality is available in the open source  
version of nginx. See the docs: [Module ngx\_http\_proxy\_module](http://nginx.org/r/proxy_bind)

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Artur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@Artur](https://www.ruby-forum.com/u/Artur)\
**Post date:** [May 10, 2016, 5:44pm UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-scalability/244601/6 "2016-05-10T17:44:45Z")

</div>

On 5/10/16 6:37 PM, Artur wrote:  
[…]

> > - add more local addresses on nginx side and use proxy\_bind to  
> > balance users between these addresses.  
> > Yes, I’ve seen this, however I didn’t catch how to dynamically  
> > assign a value to proxy\_bind from a pool of IP addresses in nginx  
> > (not Nginx Plus).

The blog post I sent has nothing -plus specific in this area.

–  
Maxim K.

---

<div class="post-metadata">

**Author:** ![Artur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@Artur](https://www.ruby-forum.com/u/Artur)\
**Post date:** [May 10, 2016, 5:57pm UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-scalability/244601/7 "2016-05-10T17:57:02Z")

</div>

Hello!

On Tue, May 10, 2016 at 05:37:55PM +0200, Artur wrote:

> Thanks for your answer.
> 
> Le 10/05/2016 à 17:04, Maxim D. a écrit :
> 
> > As long as you are using TCP/IP and have only one backend (ip +  
> > port), and only one local address on nginx side, then you are  
> > limited by the number of local ports nginx can use.  
> > I currently have nginx running on the same host that my backends.  
> > I have 4 of them listening on different ports on 127.0.0.1.  
> > In this situation may I expect 4 times 65000 simultaneous connections ?

Yes.

(Note though, that this may not be true on all OSes. And this  
also won’t be true when using proxy\_bind, as OS will have to  
choose a local port before the destination address is known.)

> > - add more local addresses on nginx side and use proxy\_bind to  
> > balance users between these addresses.  
> > Yes, I’ve seen this, however I didn’t catch how to dynamically assign a  
> > value to proxy\_bind from a pool of IP addresses in nginx (not Nginx Plus).

The blog post as linked by Maxim K. uses the split\_clients  
module, it’s not nginx-plus specific. See here for details:

> **[Module ngx\_http\_split\_clients\_module](http://nginx.org/en/docs/http/ngx_http_split_clients_module.html)**

Depending on your particular case, there may be even easier  
solutions. E.g., if you have two URIs in your application with  
more or less equal load, you can use two locations with distinct  
addresses configured statically:

```
location /one {
    proxy_pass http://127.0.0.1:8080;
    proxy_bind 127.0.0.2;
}

location /two {
    proxy_pass http://127.0.0.1:8080;
    proxy_bind 127.0.0.3;
}

```

–  
Maxim D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![Artur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@Artur](https://www.ruby-forum.com/u/Artur)\
**Post date:** [May 10, 2016, 5:49pm UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-scalability/244601/8 "2016-05-10T17:49:26Z")

</div>

Le 10/05/2016 ? 17:46, Maxim K. a ?crit :

> The blog post I sent has nothing -plus specific in this area.  
> That’s perfect. Thank you all.

–

Best regards,  
Artur.
