location ~* "(?<begin>rplocal|rposs)/([a-z0-9]{3})/([a-z0-9]{8})/(.*)$" {
rewrite "(?<begin>rplocal|rposs)/([a-z0-9]{3})/([a-z0-9]{8})/(.*)$" /$2/$3/$4 break;
if ($begin = 'rplocal') {
set $proxy http://127.0.0.1:9222;
}
if ($begin = 'rposs') {
set $proxy https://url-domain.com;
}
proxy_pass $proxy;
}
目的是通过 url 反向到不同的地址
这里补充一个可以通过的方案, 但是此方案还有冗余 rewrite, 是使用 openresty + echo 调试出来的
location ~* "(rplocal|rposs)/([a-z0-9]{3})/([a-z0-9]{8})/(.*)$" {
set $type $1;
if ($type = "rplocal") {
rewrite "^/([a-z\-]*)/(\w{3})(\w{5})/(.*)$" /$2/$3/$4 break;
proxy_pass http://127.0.0.1:9222;
}
if ($type = "rposs") {
rewrite "^/([a-z\-]*)/(\w{3})(\w{5})/(.*)$" /$2/$3/$4 break;
proxy_pass https://url-domain.com;
}
}
这种情况,我都拆成两个 location 来写