Document Caddy directive-order pitfall for well-known reverse-proxying

Caddy evaluates directives according to its own fixed directive order,
not their order in the Caddyfile. redir runs before reverse_proxy, so a
redirect elsewhere in the same site block silently shadows the
/.well-known/matrix reverse-proxying. Add a note and a handle-block
example that enforces the intended priority.

Fixes #1080

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Slavi Pantaleev
2026-07-13 15:02:20 +03:00
parent ee38b3aac2
commit 2fe710bdb4
+17
View File
@@ -155,6 +155,23 @@ example.com {
}
```
**Note**: Caddy does not process directives in the order they appear in the Caddyfile, but according to its own [directive order](https://caddyserver.com/docs/caddyfile/directives#directive-order). Notably, `redir` is evaluated before `reverse_proxy`, so a `redir` elsewhere in the same site block (a common way to send the base domain to `www.example.com` or to another site) takes precedence and breaks the well-known reverse-proxying. In such cases, wrap the directives in [`handle`](https://caddyserver.com/docs/caddyfile/directives/handle) blocks to enforce the intended priority:
```caddy
example.com {
handle /.well-known/matrix/* {
reverse_proxy https://matrix.example.com {
header_up Host {upstream_hostport}
}
}
handle {
# Everything else, e.g. a redirect to some other site
redir https://www.example.com{uri}
}
}
```
**For HAProxy**, it would be something like this:
```haproxy