is there a way to force a specific ip address to always go to the same server in upstream?

Igor Sysoev is at rambler-co.ru
Tue Sep 15 09:04:57 MSD 2009


On Tue, Sep 15, 2009 at 12:52:24PM +0800, Joshua Zhu wrote:

> Something like this?
> 
> http {
>     upstream backend {
>         server 127.0.0.1:8001;
>         server 127.0.0.1:8002;
>         server 127.0.0.1:8003;
>     }
> 
>     server {
>         listen 8080;
> 	server_name localhost;
> 	
>         location / {
>             if ($remote_addr = 127.0.0.1 ) {
>                 proxy_pass http://127.0.0.1:8003;
>                 break;
>             }
> 
>             proxy_pass http://backend;
>         }
>     }
> }

This is better:

http {
     map  $remote_addr  $back {
          default    backend;
          127.0.0.1  127.0.0.1:8003;
     }

     upstream backend {
         server 127.0.0.1:8001;
         server 127.0.0.1:8002;
         server 127.0.0.1:8003;
     }

     server {
        listen 8080;
 	server_name localhost;
 	
         location / {
             proxy_pass http://$back$request_uri;
        }
    }
}


> On Tue, Sep 15, 2009 at 11:55 AM, Ilan Berkner <iberkner at gmail.com> wrote:
> > Thanks, that's not what I mean.
> >
> > For testing purposes, we'd like to have our work computers go to a
> > particular upstream server at all times.  I think that the ip_hash directive
> > for the most part accomplishes that, but doesn't force one server over the
> > other.  Whichever one you end up with is the one you get... am I wrong?
> >
> > thanks
> >
> > On Mon, Sep 14, 2009 at 10:00 PM, Joshua Zhu <zhuzhaoyuan at gmail.com> wrote:
> >>
> >> Hi,
> >>
> >> Yes.
> >> http://wiki.nginx.org/NginxHttpUpstreamModule#ip_hash
> >>
> >> On Tue, Sep 15, 2009 at 9:42 AM, Ilan Berkner <iberkner at gmail.com> wrote:


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list