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.
Try this: