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 {
   redir /ViewPower /ViewPower/
   handle_path /ViewPower/* {

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.

3. Caddy version:


4. How I installed and ran Caddy:

As a Plugin in OPNsense

I also tried {

   rewrite * /ViewPower

still the same issue.

Any idea what I’m doing wrong?

1 Like

You probably need a rewrite like this: {
	@notViewPower not path /ViewPower*
	rewrite @notViewPower /ViewPower{uri}


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

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.