I want to handle 2 cases: test.example.com
and test.example.com/ABC
.
If the entered url is the base domain (
test.example.com
), I want toproxy_pass
a given endpoint (Let's sayexample.com/home
).If
test.example.com/ABC
is given, I want toproxy_pass
toexample.com/confirm/ABC
- test.example.com = https://example.com/home
- test.example.com/ABC = https://example.com/confirm/ABC
I made the (1) work like so:
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name test.example.com;
location / {
proxy_pass https://example.com/home;
}
}
But I couldn't figure out how to say "If $request_uri exists, proxy_pass to different endpoint". I tried:
location / {
if ($request_uri) {
proxy_pass https://example.com/confirm/$request_uri;
}
proxy_pass https://example.com/home;
}
How can I achieve this?