Thanks for trying Caddy 2!
That’s right – the file server and the reverse proxy are both terminal handlers, meaning they don’t invoke the next handler in the chain if they both match a request, and the reverse proxy is coded to come first by default when using the Caddyfile.
Right now, they match all requests (because all request paths start with
/). When do you want the file server to be used instead? Caddy doesn’t know what you want to do since you told it to use both the file server and the reverse proxy for all requests, so it just picked the reverse proxy to go first.
You have a couple options off the bat:
You can restrict either the file server or the reverse proxy to match only certain requests.
You can change the order of the directives, using
handler_order option in the global config: https://github.com/caddyserver/caddy/wiki/v2:-Documentation#global-config – you can change the order to that of appearance in the Caddyfile or hard-code your own order for the directives.
Option 1 will tell Caddy to use the file server or the reverse proxy depending on the request, whereas option 2 (without any other changes) will let you tell Caddy to use the file server instead of the reverse proxy when they both match the same request; but that makes having both in the Caddyfile redundant still.
So I think what you want to do is tell Caddy to use one or the other depending on the request, not to use both for all requests (because it can only use 1). Does that make sense?