I am trying to create a reverse proxy route using nginx-proxy and docker for OpenTripPlanner (OTP) version 1.5.0 and 2.2.0 on the same machine.
If I have a simple location block like:
location /otp2 {
proxy_pass http://127.0.0.1:8081;
}
The majority of calls OTP makes gets passed on to the upstream server, however the OTP web-app also has some hardcoded calls to http://host/otp
and http://host/images
(not http://host/otp2/otp
and http://host/otp2/images
). As they don't match an nginx location block, they fail to resolve.
How can I ensure these calls get routed to the upstream server as well?
What I've tried
Regex + rewrite
After a lot of fiddling around I settled on:
location ~^/(otp2|otp|images) {
rewrite ^(/otp2)$ $1/ permanent;
rewrite ^/(otp2)(.*) $2 break;
rewrite ^/(otp)(.*) /$1$2 break;
rewrite ^/(images)(.*) $1$2 break;
proxy_pass http://127.0.0.1:8081;
}
This works, but this prevents me from running OTP version 1.5.0 next to it, as that binary also requests http://host/otp
and http://host/images
.
Additionally, every other web-app I would run on that host that would have a route to /images
would probably be picked up by that location block.
Subdomain
I cannot make changes to the DNS, so (I assume) I can only do path-based location blocks, and not subdomains like otp2.host.com
and otp1.host.com
.
Separate location blocks
Per suggestion of one of the answerers I tried separate location blocks:
location /otp2 {
proxy_pass http://127.0.0.1:8081/;
}
location /otp2/otp {
proxy_pass http://127.0.0.1:8081/otp/;
}
location /otp2/images {
proxy_pass http://127.0.0.1:8081/images/;
}
This partially works, but leaves a few unhandled OTP requests which breaks the application (the host of the form sub1.sub2.company.country
is obfuscated in below screenshot):
