我想处理 2 种情况:test.example.com
和test.example.com/ABC
.
如果输入的 url 是基域(
test.example.com
),我想要proxy_pass
一个给定的端点(比如说example.com/home
)。如果给出,
test.example.com/ABC
我想proxy_pass
example.com/confirm/ABC
- test.example.com = https://example.com/home
- test.example.com/ABC = https://example.com/confirm/ABC
我做了(1)这样的工作:
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name test.example.com;
location / {
proxy_pass https://example.com/home;
}
}
但我不知道怎么说“如果 $request_uri 存在,proxy_pass 到不同的端点”。我试过了:
location / {
if ($request_uri) {
proxy_pass https://example.com/confirm/$request_uri;
}
proxy_pass https://example.com/home;
}
我怎样才能做到这一点?