Directives in an Caddyfile can have "matchers" that limit them to specific requests. This lets Caddy 2 serve different content for different paths, but what happens when multiple directives match the same request?
If I want to serve a mostly-static website using Caddy 2, but forward an /api/
area to some Node.js process, my Caddyfile might look like this:
fake-example.edge.app {
root * /var/www/example
reverse_proxy /api/* localhost:9000
file_server *
}
A request to /api/user
would match both the file_server *
and reverse_proxy /api/*
matchers, so it's not clear whether the request will go to the filesystem or the Node.js process.
I couldn't find anything in the Caddy 2 documentation that describes what should happen. In my own testing, the results seem to depend on the order the directives appear in the file, with earlier entries "winning". What is supposed to happen? If it's "undefined behavior", is there a better way to write this file to avoid the ambiguity?