<div dir="ltr"><div><div><div><div><div><div>Hi Maxim,<br><br></div>Thanks for reply.<br><br></div>Number of IPs are not fixed so it is not possible to define upstream and map block I think. I am trying to implement completely dynamic configuration using lua module.<br>
<br><br></div>Is it possible to use variable in upstream block like this?<br></div>upstream backend {<br></div> server $IP;<br></div> keepalive 2;<br><div><div>}<br><br>location / {<br>
proxy_pass <a href="http://backend">http://backend</a>;<br>
proxy_http_version 1.1;<br>
proxy_set_header Connection "";<br>}<br><br><br></div><div>Thanks,<br></div><div>Makailol<br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 2, 2014 at 7:29 PM, Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello!<br>
<div><div class="h5"><br>
On Wed, Apr 02, 2014 at 06:55:42PM +0530, Makailol Charls wrote:<br>
<br>
> Hi,<br>
><br>
> Can some one provide me an example to set keep alive connection between<br>
> Nginx(reverse proxy) and backend server?<br>
><br>
> I can not use upstream module as my backend IP is dynamic based on<br>
> variable. So I can not use keepalive directive of upstream.<br>
><br>
> I have used below directive in location block.<br>
> proxy_pass http://$IP ;<br>
<br>
</div></div>Use of keepalive connections require upstream{} block to be<br>
defined, see here for examples:<br>
<br>
<a href="http://nginx.org/r/keepalive" target="_blank">http://nginx.org/r/keepalive</a><br>
<br>
As long as list of backend ip addresses is limited, you may define<br>
appropriate upstream{} blocks for each backend, and use upstream's<br>
name in a variable, e.g.:<br>
<br>
upstream backend1 {<br>
server 192.168.0.1;<br>
keepalive 2;<br>
}<br>
<br>
...<br>
<br>
map $IP $backend {<br>
192.168.0.1 backend1;<br>
...<br>
}<br>
<br>
location / {<br>
proxy_pass http://$backend;<br>
proxy_http_version 1.1;<br>
proxy_set_header Connection "";<br>
}<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Maxim Dounin<br>
<a href="http://nginx.org/" target="_blank">http://nginx.org/</a><br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</font></span></blockquote></div><br></div>