在有些时候,需要根据请求url参数来进行不同的url重定向,当时花费的不少时间进行相关处理,下面做一下记录:
location / {
set $newIp "192.168.72.102:80";
if ($query_string ~ appversion=(1.4.0)){
set $newIp "192.168.72.102:8080";
}
proxy_pass "http://$newIp";
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
或:
location / {
set $newIp "192.168.72.102:80";
if ($args ~ appversion=(1.4.0)){
set $newIp "192.168.72.102:8080";
}
proxy_pass "http://$newIp";
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
这也算一个变相的负载均衡吧