The effect is that when I visit the site at https://krx.hxwd.org, the server running locally on port 8088 is called, with the path /exist/apps/tls-app added before the request path, so
a call to
https://krx.hxwd.org/index.html
results in a call to
http:localhost:8080/exist/apps/tls-app/index.html
4. Error messages and/or full log output:
There is no error message, but the path called seems to be only
http:localhost:8080/exist/index.html
5. What I already tried:
I have tried several ways to form the reverse_proxy path, but nothing solved the problem.
The configuration did work nicely, but now I want to switch to caddy because I want to add the conf for another vhost at code.hxwd.org
First, remove the / matcher. That will only match on exactly / and nothing else. Caddy uses exact path matching. Omitting it is the same as *, meaning match everything.
Second, Caddy v2’s proxy handler doesn’t support rewrites on its own. Instead, you need to use a rewrite handler to change the path before proxying. Looks like this:
rewrite * /exist/apps/tls-app{uri}
Just put that before your proxy, and remove the path portion from the proxy. Should work just fine.
Dear Francis,
Thank you so much for your answer. This is very helpful, as I now understand why none of the reverse_proxy examples I found had a path component!
My system is almost working now, except for one small glitch:
If no document is specified, that is if the URI ends with a slash or has no document ending, I will need to request the “index.html” document.
I tried to add a try_files statement like this:
Note that the omission of / besides the placeholders is intentional, because in both cases, they include the / at their boundaries. {uri} always starts with a /, and since we matched path as ending with a /, we know it will already have it.
Also to note, this relies on the Caddyfile directive sorting logic. Directives will be ordered based on the length of their path matchers. Since the first one has a path matcher, it will be ordered first; the second rewrite doesn’t have a path matcher so it will be ordered last. If you were to add another rewrite for some other reason, be aware that if it uses a path longer than 2 characters, it will be ordered before your index.html. You can solve that by wrapping them in route { } which will guarantee the order they’re handled.
Hmm, unfortunately this does not solve my problem, calling the domain without any path component still does an internal direct at some point, which is adding an unwanted /exist to the request (this is coming from the upstream server).
I also realized there is another problem, with the cookies used for maintaining login state:
In apache I have
That’s the only thing from the nginx example in their docs that Caddy doesn’t do automatically. The exist app might be looking for that header to decide how to handle its requests.
Anyways I’m just making guesses at this point. If it still doesn’t work, please elaborate and be specific about the behaviour you’re seeing, with logs etc.
Still working on this issue. I tried your solution, but that did not solve the problem, the nginx headers do not have any special meaning within exist-db. The crucial point I think is that the path in the cookie is wrong, for the login to work I need to have the root path “/” instead of the path from the backend, which is “/exist”. So while going back through caddy, I need to instruct it to remove this part.
I still have the production server running behind apache, so I made a comparison of the cookies as seen in the Firefox developer tools.