How to proxy including subpath

1. The problem I’m having:

I want to handle requests coming to subdomain.example.com to localhost:8080/subpath. How can I migrate this?

The previous apache configuration was as follows:

<VirtualHost *:80>
ServerName subdomain.example.com

ProxyPreserveHost On
ProxyPassReverse / http://localhost:8080/subpath/
ProxyPass / http://localhost:8080/subpath/

2. Error messages and/or full log output:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

3. Caddy version:

v2.8.4

4. How I installed and ran Caddy:

caddy reload

a. System environment:

windows 11

b. Command:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

c. Service/unit/compose file:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

d. My complete Caddy config:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

5. Links to relevant resources:

Howdy @any, welcome to the Caddy community.

Proxying from subdomain.example.com/ to localhost:8080/subpath/, and then doing ProxyPassReverse, in Caddy, means:

  1. In a site block for subdomain.example.com
    (See Caddyfile Concepts — Caddy Documentation)
  2. rewrite the URI to add /subpath to the beginning
    (See rewrite (Caddyfile directive) — Caddy Documentation)
  3. reverse_proxy to localhost:8080
    (See reverse_proxy (Caddyfile directive) — Caddy Documentation)
  4. Intercept Location header responses and rewrite them with header_down
    (See reverse_proxy (Caddyfile directive) — Caddy Documentation)