Reputation: 7237
Suppose that i have to upstream source
upstream first {
}
upstream second {
}
And then in server
block
map $geoip_country_code $is_china {
default no;
CN yes;
}
What I would like to achieve is if $is_china
, use a different upstream
proxy_pass http://$preferred_host/;
I can't figure how to do this with nginx.
Upvotes: 3
Views: 909
Reputation: 101
map
might be just sufficient. Have you tried the following?
map $geoip_country_code $preferred_host {
default first;
CN second;
}
Upvotes: 4
Reputation: 7237
Turn out I can use if
in nginx
set $preferred_host http://first;
if ($is_china) {
set $preferred_host http://second;
}
location / {
proxy_pass $preferred_host/;
...
}
Upvotes: 1