根 location 中要判断客户端 UA ,根据不同 UA 转发到不同服务(如:aaa.com/bbb.com ),配置时写两个 proxy_set_header 会报语法错误。应该怎么实现呢,请大神赐教。
location / {
set $mobile_rewrite do_not_perform;
if ($http_user_agent ~* '(windows|Windows|Intel Mac OS X)') {
set $mobile_rewrite perform;
}
if ($args ~ h5=1){
set $mobile_rewrite do_not_perform;
}
if ($mobile_rewrite = perform) {
#proxy_pass http://10.20.6.164:8080;
proxy_pass http://aaa.com;
}
proxy_set_header Host "bbb.com";
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://10.20.127.34/;
}
1
poembre 2022-07-19 13:51:15 +08:00
- 如果你用 openresty 的话 , 可以这样,更加灵活
``` location / { set $upstream_url 'http://10.20.127.34'; access_by_lua_block { if string.find(xxx,xxx) then ngx.var.upstream_url = "http://www.baidu.com" end } proxy_pass $upstream_url; } ``` |
2
humbass 2022-07-19 22:44:40 +08:00
用 Stream 模块实现,判断 UNI 即可。
|