我希望处理两种情况:
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存在,则代理传输到不同的端点”。我尝试了:
location / {
if ($request_uri) {
proxy_pass https://example.com/confirm/$request_uri;
}
proxy_pass https://example.com/home;
}
我该如何实现这个目标?