How to proxy web applications with basepath

1. The problem I’m having:

I run a web service that contains basepath paths. Using the following caddy configuration it is accessible via the domain name, but redirects cause the browser address bar to expose the basepath. how do I change the configuration to make it accessible and not expose the basepath to the browser?

domain.com {
        redir / /app/ 302
        reverse_proxy /app/*  ip:port
}

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.9.1

4. How I installed and ran Caddy:

a. System environment:

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:

You’d have to start rewriting the HTML content sent to your browser and remove the <base …> tag from it.

Take a look at replace-response.

1 Like

Do you think handle_path would work in this context?

handle_path would strip the /app/ path so that the back-end would not see it. But you could still run into The "subfolder problem", OR, "why can't I reverse proxy my app into a subfolder?"

1 Like

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