# Dynamic upstream configuration

**URL:** <https://www.ruby-forum.com/t/dynamic-upstream-configuration/228305>\
**Category:** NGINX\
**Created:** [April 17, 2013, 10:42am UTC](https://www.ruby-forum.com/t/dynamic-upstream-configuration/228305 "2013-04-17T10:42:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mamoos1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc79bd/32.png) [@mamoos1](https://www.ruby-forum.com/u/mamoos1)\
**Post date:** [April 17, 2013, 10:42am UTC](https://www.ruby-forum.com/t/dynamic-upstream-configuration/228305/1 "2013-04-17T10:42:51Z")

</div>

Hi,

I have an nginx configured as a reverse proxy using proxy\_pass.  
This is a dynamic reverse proxy, it fetches content for users in  
accordance  
to the HOST header in the requests.  
The problem I encountered is that the backends are normally SSL, and  
every  
request that goes has to re-handshake (since there is no keep-alive  
between  
nginx and the backend servers).  
I know that I can configure keep-alive with upstream - but that requires  
me  
to know upfront which servers will be used (which I don’t, since I  
dynamically fetch content according to headers).  
Is there a way to configure that the proxy will keep-alive connections  
with  
backend servers dynamically, or for some time?

Thanks,  
Roy.

Posted at Nginx Forum:

> **[Dynamic upstream configuration](https://forum.nginx.org/read.php?2,238424,238424#msg-238424)**
>
> Hi, I have an nginx configured as a reverse proxy using proxy\_pass. This is a dynamic reverse proxy, it fetches content for users in accordance to the HOST header in the requests. The problem I encountered is that the backends are normally SSL, and...

---

<div class="post-metadata">

**Author:** ![mamoos1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc79bd/32.png) [@mamoos1](https://www.ruby-forum.com/u/mamoos1)\
**Post date:** [April 30, 2013, 4:04pm UTC](https://www.ruby-forum.com/t/dynamic-upstream-configuration/228305/2 "2013-04-30T16:04:26Z")

</div>

A shame that no one has a solution for this…  
It’s a really big performance hit whenever backend servers are https and  
nginx simply renegotiates SSL for each request.

Is there any plan to support this? Some sort of backend connection  
pooling  
with SSL?

Posted at Nginx Forum:

> **[Re: Dynamic upstream configuration](https://forum.nginx.org/read.php?2,238424,238746#msg-238746)**
>
> Hi, I have an nginx configured as a reverse proxy using proxy\_pass. This is a dynamic reverse proxy, it fetches content for users in accordance to the HOST header in the requests. The problem I encountered is that the backends are normally SSL, and...

---

<div class="post-metadata">

**Author:** ![mamoos1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc79bd/32.png) [@mamoos1](https://www.ruby-forum.com/u/mamoos1)\
**Post date:** [April 30, 2013, 5:19pm UTC](https://www.ruby-forum.com/t/dynamic-upstream-configuration/228305/3 "2013-04-30T17:19:47Z")

</div>

No it does not unless you don’t configure a shared SSL session cache.  
[http://nginx.org/en/docs/http/ngx\_http\_ssl\_module.html#ssl\_session\_cache](http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_session_cache)

I’m assuming that the upstream servers are Nginx also.  
If not adapt to the appropriate server session cache setup.

----appa

---

<div class="post-metadata">

**Author:** ![mamoos1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc79bd/32.png) [@mamoos1](https://www.ruby-forum.com/u/mamoos1)\
**Post date:** [May 13, 2013, 3:13pm UTC](https://www.ruby-forum.com/t/dynamic-upstream-configuration/228305/4 "2013-05-13T15:13:38Z")

</div>

Hi!

Unfortunately, I didn’t find a very good solution for this, but, in  
nginx  
1.4+ the issue with SSL backend keepalive was fixed - so if you have a  
list  
of all your possible servers, your configuration file will look  
horrible,  
but you can achieve this by having all the backend servers defined as  
upstreams with different “server” clauses for each of the proxies.

Cheers,

- Roy

Posted at Nginx Forum:

> **[Re: Dynamic upstream configuration](https://forum.nginx.org/read.php?2,238424,239143#msg-239143)**
>
> Hi, I have an nginx configured as a reverse proxy using proxy\_pass. This is a dynamic reverse proxy, it fetches content for users in accordance to the HOST header in the requests. The problem I encountered is that the backends are normally SSL, and...

---

<div class="post-metadata">

**Author:** ![mamoos1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc79bd/32.png) [@mamoos1](https://www.ruby-forum.com/u/mamoos1)\
**Post date:** [May 13, 2013, 3:07pm UTC](https://www.ruby-forum.com/t/dynamic-upstream-configuration/228305/5 "2013-05-13T15:07:47Z")

</div>

## mamoos1 Wrote:

[snip…]

> I know that I can configure keep-alive with upstream - but that  
> requires me to know upfront which servers will be used (which I don’t,  
> since I dynamically fetch content according to headers).  
> Is there a way to configure that the proxy will keep-alive connections  
> with backend servers dynamically, or for some time?

I’m facing a similar issue right now where I need to enable  
persistent/keepalive connections to a dynamic set of upstreams. This is  
not running SSL, but for various reasons upstream servers are slow at  
establishing connections and persistent connections are a real  
performance boost.

We dynamically find the upstream using lua scripting. What I’d like  
is to dynamically define an upstream including keepalive (ideally in  
lua).

Has anyone found a way to achieve this, or is it simple not possible at  
the moment?

- Karl

Posted at Nginx Forum:

> **[Re: Dynamic upstream configuration](https://forum.nginx.org/read.php?2,238424,239142#msg-239142)**
>
> Hi, I have an nginx configured as a reverse proxy using proxy\_pass. This is a dynamic reverse proxy, it fetches content for users in accordance to the HOST header in the requests. The problem I encountered is that the backends are normally SSL, and...
