Forum: NGINX how to use keepalive with Nginx revers proxy?

7c401942fa6feef9792b64ba0230156b?d=identicon&s=25 Makailol Charls (Guest)
on 2014-04-02 15:26
(Received via mailing list)
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
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2014-04-02 16:00
(Received via mailing list)
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/
7c401942fa6feef9792b64ba0230156b?d=identicon&s=25 Makailol Charls (Guest)
on 2014-04-03 06:02
(Received via mailing list)
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
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2014-04-03 15:02
(Received via mailing list)
Hello!

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

> upstream backend {
>     server $IP;
>     keepalive 2;
> }

No, this won't work.

>
> > > Nginx(reverse proxy) and backend server?
> > http://nginx.org/r/keepalive
> >     ...
> >     }
> >
> > --
> > Maxim Dounin
> > http://nginx.org/
> >
> > _______________________________________________
> > nginx mailing list
> > nginx@nginx.org
> > http://mailman.nginx.org/mailman/listinfo/nginx
> >

> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx


--
Maxim Dounin
http://nginx.org/
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.