Web / Caddy Server Interview questions
What is the difference between Caddy's global options block and site address blocks?
| Aspect | Global options block | Site address block |
| Syntax position | First, unlabeled { } block at the very top of the file | Block labeled with a domain/address, e.g. example.com { } |
| Scope | Server-wide settings: admin API, ACME email/CA, default ports, logging defaults | Behavior for requests to that specific address only |
| Directives allowed | Global options only (admin, email, acme_ca, debug, etc.) | Regular site directives (reverse_proxy, file_server, header, etc.) |
| Cardinality | At most one per Caddyfile | One block per site/address, many allowed |
{ email admin@example.com admin off } example.com { reverse_proxy localhost:4000 } static.example.com { root * /var/www/static file_server }
Caddy tells the two apart by position and content: if the very first block in the file has no address label before it, it's parsed as global options, and everything after it must be labeled site blocks. Putting a site-level directive in the global block, or a global option in a site block, is a config error.
More Related questions...