Reverse_proxy subfolder rewrite

Continuing the discussion from Attempting to reverse proxy to a folder w/ Caddy 2:

I am using the docker image caddy:2.3.0-alpine.

The accepted solution from the previous discussion is this

but I am getting Error during parsing: Wrong argument count or unexpected line ending after 'rewrite' when trying this

  bar.foo.com {
    header Cache-Control max-age=3600
    rewrite /some/folder{uri}
    reverse_proxy {
      to https://other.com
    }
  }

And fair enough - looking at the docs it seems like rewrite needs a 2nd arg. So I changed it to:

bar.foo.com {
    header Cache-Control max-age=3600
    rewrite * /some/folder{uri}
    reverse_proxy {
      to https://other.com
    }
  }

But now while a curl works just fine curl https://other.com/some/folder/FOO on the upstream, caddy is giving a 421 status error for curl https://bar.foo.com/FOO.

I don’t quite understand why. Any thoughts on how to debug this?

I answered this on Discord :wink:

@tcurdt if your upstream is expecting to see other.com as the Host/SNI, then you need to add this to your reverse_proxy options:

header_up Host {http.reverse_proxy.upstream.hostport}
1 Like

Indeed you did :slight_smile: Thanks again!

1 Like

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