Reverse Proxy with path/subdirectory

1. The problem I’m having:

I’ve tried everything that is possible, rewrite, handlepath etc. but for the life of me I’m unable to get this reverse proxy to work

this is the Caddyfile

ups.foo.net {
   redir /ViewPower /ViewPower/
   handle_path /ViewPower/* {
   reverse_proxy 192.168.2.188:15178
   }
}

2. Error messages and/or full log output:

Whatever i do i’m getting to the root of the tomcat server & not the application. If I append the /ViewPower/ it works e.g. https://ups.foo.net/ViewPower/

3. Caddy version:

v2.7.6

4. How I installed and ran Caddy:

As a Plugin in OPNsense

I also tried

ups.foo.net {

   rewrite * /ViewPower
   reverse_proxy http://192.168.2.188:15178
}

still the same issue.

Any idea what I’m doing wrong?

1 Like

You probably need a rewrite like this:

ups.foo.net {
	@notViewPower not path /ViewPower*
	rewrite @notViewPower /ViewPower{uri}

	reverse_proxy 192.168.2.188:15178
}

You were close with the last one, but you need to add {uri} to preserve the original request URL.

The trouble though is that if the upstream app has links with /ViewPower already prefixed, then Caddy would double-up the prefix, unless we use a matcher to not do the rewrite if the path is already there.

But ideally, if it’s possible to configure the upstream app, it would be better if it didn’t require the path.

Welcome back, Master Yoda!

What is the output of curl -v for requests that you’d expect to work? What URLs does the application expect – is it with or without the /ViewPower/ prefix?

Note that handle_path strips the prefix /ViewPower/.

Also it’s possible your application is redirecting if the proxy is misconfigured for the application, like with regards to Host headers or URI or something.

the URL required /ViewPower/ to work, without that it just shows the tomcat default page

there was a typo in my earlier post, i did have the {uri} there but it went to the default tomcat home page… but your solution worked for me, thanks a ton