Matcher Interface
Matchers implement theRequestMatcherWithError interface:
Matchers MUST NOT modify the request, with the only exception being its context.
Matcher Sets
A matcher set is a group of matchers that must all match (AND logic):example.com OR requests to /public/* on any host.
Host Matcher
Module ID:http.matchers.host
Matches requests by the Host header value (case-insensitive).When used in a top-level HTTP route, qualifying domain names may trigger automatic HTTPS, which automatically provisions and renews certificates.Wildcards (
*) may be used to represent exactly one label of the hostname:*matcheslocalhostorinternalbut notexample.com*.example.commatchesfoo.example.combut notfoo.bar.example.com
Path Matcher
Module ID:http.matchers.path
Case-insensitive exact path matching (not prefix-based). Wildcards (
*) supported:/prefix/*- Prefix match*.suffix- Suffix match*/contains/*- Substring match/accounts/*/info- Globular match
Path Regexp Matcher
Module ID:http.matchers.path_regexp
Method Matcher
Module ID:http.matchers.method
Matches requests by HTTP method (GET, POST, PUT, DELETE, etc.).
Query Matcher
Module ID:http.matchers.query
Matches requests by URI query string. Keys are exact, values support wildcards.
Query string values are arrays because repeated keys are valid. The matcher succeeds if any configured value matches.
Header Matcher
Module ID:http.matchers.header
Matches requests by header fields. Performs fast, exact string comparisons. Wildcards supported for prefix/suffix/substring matching.
nullvalue - header must not exist- Empty array - header must exist (any value)
- Array of values - match if any value matches
Header Regexp Matcher
Module ID:http.matchers.header_regexp
Matches requests using regular expressions on header fields.Keys are header field names, values are
MatchRegexp objects with name and pattern fields.Adds placeholders like {http.regexp.name.capture_group}.Protocol Matcher
Module ID:http.matchers.protocol
Matches requests by protocol. Recognized values:
http- HTTP (not HTTPS)https- HTTPSgrpc- gRPC (Content-Type: application/grpc)http/1,http/1.1- Specific HTTP versionshttp/2,http/3- HTTP/2 or HTTP/3http/2+- HTTP/2 or later
TLS Matcher
Module ID:http.matchers.tls
Matches HTTP requests based on the underlying TLS connection state.If this matcher is specified but the request didn’t come over TLS, it will never match.
Matches if the TLS handshake has completed. QUIC 0-RTT early data may arrive before handshake completion.
Not Matcher
Module ID:http.matchers.not
Matches requests by negating the results of its matcher sets. Each matcher set is OR’ed.Structure is an array of matcher set objects:This matches if the path is NOT
/admin/* AND the IP is NOT in 192.168.0.0/16.Remote IP Matcher
Module ID:http.matchers.remote_ip
Matches requests by the client’s IP address. Supports CIDR notation and IP ranges.
File Matcher
Module ID:http.matchers.file
Matches requests if the requested file exists on the filesystem.
Expression Matcher
Module ID:http.matchers.expression
Matches requests using CEL (Common Expression Language) expressions. Provides access to all request properties and Caddy placeholders.
Configuration Examples
Multiple Matchers (AND)
Multiple Matcher Sets (OR)
Complex Matching
api.example.com/v1/* but NOT /v1/health.
For large host lists (>100), Caddy optimizes matching using binary search for exact matches and linear search for wildcards.