-
-
Notifications
You must be signed in to change notification settings - Fork 185
Description
Document here https://caddyserver.com/docs/caddyfile/directives#directive-order says:
Same-named directives are sorted according to their matchers.
The highest priority is a directive with a single path matcher.
A directive with any other matcher is sorted next, in the order it appears in the Caddyfile. This includes path matchers with multiple values, and named matchers.
Based on the description, one would logically assume that, when sorting same named directive, like handle
under the same site block, like:
example.com {
@UA header User-Agent *something*
handle @UA {
reverse_proxy 127.0.0.1:8080
}
handle /path1 {
reverse_proxy 127.0.0.1:8081
}
handle /path2 {
reverse_proxy 127.0.0.1:8082
}
}
path1
and path2
would have highest priority, after all they have a single path matcher. @UA
as a named matcher would be sorted next, based on the order it appeared in the caddyfile.
However in reality, the @UA matcher is the first one to be handled, which contradicts what is being said in the documents.
On the forum a dev told me that (https://caddy.community/t/confusion-about-directive-order/30985):
If they’re different, the matcher defined first stays before the other. https://github.com/caddyserver/caddy/blob/master/caddyconfig%2Fhttpcaddyfile%2Fdirectives.go#L496-L500
Maybe, the document could use some touch up for clarity regarding the sorting order?