Web / Caddy Server Interview questions
What is the difference between snippets and named matchers in a Caddyfile?
| Aspect | Snippet | Named matcher |
| Symbol | (name) in parentheses | @name with an at sign |
| What it holds | A reusable block of one or more directives | A reusable request-matching condition |
| Where used | Imported with import name inside a site block | Passed as an argument to a directive, e.g. header @images ... |
| Typical purpose | Avoid repeating the same set of directives across sites | Avoid repeating the same matching logic across directives |
(cors) { header Access-Control-Allow-Origin "*" } @static path *.css *.js *.png api.example.com { import cors header @static Cache-Control "max-age=86400" reverse_proxy localhost:4000 }
In short, a snippet packages directives for reuse across sites, while a named matcher packages a condition for reuse across directives within (or across) a site. They solve different repetition problems and are often combined in larger Caddyfiles.
More Related questions...