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.
map might be just sufficient. Have you tried the following?
map $geoip_country_code $preferred_host {
default first;
CN second;
}
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/;
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With