Caddy Reverse Proxy - subdirectory should point to another host

1. The problem I’m having:

I’m having a small problem with the Caddy Reverse Proxy. I want to redirect to another machine by accessing a subdirectory (like “www.domain.com/subdirectory”). I can’t get it to work.

The following code works in caddyfile (without call a subdirectory):

www.domain.com {
	uri strip_prefix /foo
	reverse_proxy {
		to https://synology-nas.local:5001
		transport http {
			tls_insecure_skip_verify
		}
	}
}

When I now access "https://www.domain.com/foo" in my browser, it correctly redirects to "https://synology-nas.local:5001" and a login window appears.

What doesn't work in caddyfile:
www.domain.com {
	handle /foo {
		uri strip_prefix /foo
		reverse_proxy {
			to https://synology-nas.local:5001
			transport http {
				tls_insecure_skip_verify
			}
		}
	}
}

When I access "https://www.domain.com/foo" in my browser, a blank white page is displayed.
I've also tested this with other destinations (Fritz!Box, Proxmox PVE), which also didn't work. However, if the destination is a simple HTML website, then this method works. It's just more complex destinations that don't work.
I've already tried several settings (for example, "route" instead of "handle" or "replace" instead of "strip_prefix"), but all without success. I'm really hoping someone here can help. If you have any further questions, I'd be happy to answer them.
Greetings, Peter

Additional:

Caddy version: Caddy v2.11.2

Installed with docker.

Oh, we’ve had this the other day. See if the solution there helps.

Hi,

Unfortunately, this solution doesn’t work either; the page remains blank. It seems to be related to the “handle /foo” part. If I remove that, it works. Could it be that the “header_up” parameters need to be different, or is something else missing?

Greetings, Peter

www.domain.com {

  redir /foo /foo/

  handle_path /foo/* {
    reverse_proxy https://synology-nas.local:5001 {
      transport http {
        tls_insecure_skip_verify
      }
    }
  }
}

Hi,

<br/>
A huge thank you to timelordx. That was exactly the solution to my problem. It works perfectly. My problem is solved. Thank you so much!
<br/>
Greetings, Peter