How to make a reverse proxy on a specific route properly?

1. The problem I’m having:

I’m trying to make a reverse proxy to localhost on a specific route in my app. Let’s say we have a route named /app that should forward to localhost:3000 with the following code:

localhost {
  handle /app {
    reverse_proxy: http://localhost:3000
  }
}

Then caddy forwards /app to my app while it expects / to be the root. I tried to use the strip_prefix function like this:

localhost {
  handle /app {
    uri strip_prefix /app
    reverse_proxy: http://localhost:3000
  }
}

But then redirects don’t work. Should I do something to fix them or does caddy have some more built in way to handle this better?

2. Error messages and/or full log output:

Not relevant

3. Caddy version:

v2.10.2 h1:g/gTYjGMD0dec+UgMw8SnfmJ3I9+M2TdvoRL/Ovu6U8=

4. How I installed and ran Caddy:

Not relevant

a. System environment:

Not relevant

b. Command:

Not relevant

d. My complete Caddy config:

Already mentioned

1 Like

I’d say it’s relevant because I don’t think that reverse_proxy: syntax you’re using it correct.

1 Like

Ah sorry i typed it wrong, it was not like that in my real code.

See this article

2 Likes

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