server {
listen 80;
server_name ~^(?<custom>.+)\.(test)?website\.com$;
location ~ ^/event/(\d+)$ {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_intercept_errors on;
# This is the problematic block
# This conditional breaks the whole location block.
# If I commented the if statement, the default proxy_pass works.
if ($http_user_agent ~* iphone|android) {
# the proxy_pass indeed works, tested on development machine
proxy_pass http://frontends/userland/mobile/event/$1;
break;
}
# When above if conditional is enabled, this fails.
proxy_pass http://frontends/userland/event/$1;
}
}
注意到 server_name 中的子域匹配器几乎是一个通配符。
为什么 if 条件不起作用?如果我正在做的事情是错误的,那么重写它的最佳方法是什么?
Nginx 版本:1.2.0