Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Do you have any idea if there is any easier solution to pass the requests to different upstreams based on the visitor's ip address?

The only solution that I found at the moment is:

upstream live {
    ip_hash;
    server 10.0.0.1;
}

upstream test {
    ip_hash;
    server 10.0.0.2;
}

location / {
    if ($remote_addr = "10.0.0.101") {
        proxy_pass http://test;
    }
    proxy_pass http://live;
    // the rest of the bla bla
}

This solves the problem if you have just on "location" and just one ip address that should go to the "test" upstream. I tried the if statement when including the config files (not working). I also tried to put the if when the upstreams are declared (same, not working).

So if someone is doing something similar, help would be appreciated (I'm sure I'm not the only one with this problem). I need this solution for our developers to test on the real env ... and that's because the payment solution that we are using allows us to send requests only from the current infrastructure.

Thanks.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Try this:

    geo $upstream_addr {
           10.0.0.101/32 test;
           default live;
    }

...
            location / {
                    proxy_pass http://$upstream_addr;
                    ...
            }
share|improve this answer
    
in this case you don't need "upsteam {}" blocks. Just replace "live" and "test" with appropriate backend address. –  Vadim Dec 8 '11 at 10:55
    
you're a life saviour! –  MihaiM Dec 8 '11 at 11:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.