how to use keepalive with Nginx revers proxy?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

how to use keepalive with Nginx revers proxy?

Makailol Charls
Hi,

Can some one provide me an example to set keep alive connection between Nginx(reverse proxy) and backend server?

I can not use upstream module as my backend IP is dynamic based on variable. So I can not use keepalive directive of upstream.

I have used below directive in location block.
proxy_pass http://$IP ;

Thanks,
Makaikol

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: how to use keepalive with Nginx revers proxy?

Maxim Dounin
Hello!

On Wed, Apr 02, 2014 at 06:55:42PM +0530, Makailol Charls wrote:

> Hi,
>
> Can some one provide me an example to set keep alive connection between
> Nginx(reverse proxy) and backend server?
>
> I can not use upstream module as my backend IP is dynamic based on
> variable. So I can not use keepalive directive of upstream.
>
> I have used below directive in location block.
> proxy_pass http://$IP ;

Use of keepalive connections require upstream{} block to be
defined, see here for examples:

http://nginx.org/r/keepalive

As long as list of backend ip addresses is limited, you may define
appropriate upstream{} blocks for each backend, and use upstream's
name in a variable, e.g.:

    upstream backend1 {
        server 192.168.0.1;
        keepalive 2;
    }

    ...

    map $IP $backend {
        192.168.0.1  backend1;
        ...
    }

    location / {
        proxy_pass http://$backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: how to use keepalive with Nginx revers proxy?

Makailol Charls
Hi Maxim,

Thanks for reply.

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.


Is it possible to use variable in upstream block like this?
upstream backend {
    server $IP;
    keepalive 2;
}

location / {
    proxy_pass http://backend;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
}


Thanks,
Makailol


On Wed, Apr 2, 2014 at 7:29 PM, Maxim Dounin <[hidden email]> wrote:
Hello!

On Wed, Apr 02, 2014 at 06:55:42PM +0530, Makailol Charls wrote:

> Hi,
>
> Can some one provide me an example to set keep alive connection between
> Nginx(reverse proxy) and backend server?
>
> I can not use upstream module as my backend IP is dynamic based on
> variable. So I can not use keepalive directive of upstream.
>
> I have used below directive in location block.
> proxy_pass http://$IP ;

Use of keepalive connections require upstream{} block to be
defined, see here for examples:

http://nginx.org/r/keepalive

As long as list of backend ip addresses is limited, you may define
appropriate upstream{} blocks for each backend, and use upstream's
name in a variable, e.g.:

    upstream backend1 {
        server 192.168.0.1;
        keepalive 2;
    }

    ...

    map $IP $backend {
        192.168.0.1  backend1;
        ...
    }

    location / {
        proxy_pass http://$backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: how to use keepalive with Nginx revers proxy?

Maxim Dounin
Hello!

On Thu, Apr 03, 2014 at 09:31:08AM +0530, Makailol Charls wrote:

> Hi Maxim,
>
> Thanks for reply.
>
> 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.
>
>
> Is it possible to use variable in upstream block like this?
> upstream backend {
>     server $IP;
>     keepalive 2;
> }

No, this won't work.

>
> location / {
>     proxy_pass http://backend;
>     proxy_http_version 1.1;
>     proxy_set_header Connection "";
> }
>
>
> Thanks,
> Makailol
>
>
> On Wed, Apr 2, 2014 at 7:29 PM, Maxim Dounin <[hidden email]> wrote:
>
> > Hello!
> >
> > On Wed, Apr 02, 2014 at 06:55:42PM +0530, Makailol Charls wrote:
> >
> > > Hi,
> > >
> > > Can some one provide me an example to set keep alive connection between
> > > Nginx(reverse proxy) and backend server?
> > >
> > > I can not use upstream module as my backend IP is dynamic based on
> > > variable. So I can not use keepalive directive of upstream.
> > >
> > > I have used below directive in location block.
> > > proxy_pass http://$IP ;
> >
> > Use of keepalive connections require upstream{} block to be
> > defined, see here for examples:
> >
> > http://nginx.org/r/keepalive
> >
> > As long as list of backend ip addresses is limited, you may define
> > appropriate upstream{} blocks for each backend, and use upstream's
> > name in a variable, e.g.:
> >
> >     upstream backend1 {
> >         server 192.168.0.1;
> >         keepalive 2;
> >     }
> >
> >     ...
> >
> >     map $IP $backend {
> >         192.168.0.1  backend1;
> >         ...
> >     }
> >
> >     location / {
> >         proxy_pass http://$backend;
> >         proxy_http_version 1.1;
> >         proxy_set_header Connection "";
> >     }
> >
> > --
> > Maxim Dounin
> > http://nginx.org/
> >
> > _______________________________________________
> > nginx mailing list
> > [hidden email]
> > http://mailman.nginx.org/mailman/listinfo/nginx
> >

> _______________________________________________
> nginx mailing list
> [hidden email]
> http://mailman.nginx.org/mailman/listinfo/nginx


--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: how to use keepalive with Nginx revers proxy?

vedranf
I have the same question, any update on it. I am using Lua and Redis for the
reverse proxy lookup and don't define upstream. How can we use keepalive?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,248924,263444#msg-263444

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: how to use keepalive with Nginx revers proxy?

vedranf
I have the same issue. I use Lua and Redis for the reverse proxy lookup and
don't use upstream. How to use keepalive then?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,248924,263445#msg-263445

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: how to use keepalive with Nginx revers proxy?

Maxim Dounin
Hello!

On Sun, Dec 13, 2015 at 09:28:27PM -0500, winghokwan wrote:

> I have the same issue. I use Lua and Redis for the reverse proxy lookup and
> don't use upstream. How to use keepalive then?

The only way now is to define upstream{} blocks in advance, and
then provide appropriate upstream{} block name from your dynamic
lookup code.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx