caddyserver/caddy · error
server block without any key is global configuration, and…
Error message
server block without any key is global configuration, and if used, it must be first
What it means
A Caddyfile server block with zero keys (the global options block) was encountered but it is not the first block. Only one global options block is allowed and it must come first, so Setup rejects the config.
Solutions
- Move the global options block (the block with no keys) to the very top of the Caddyfile, before any site blocks.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at caddyconfig/httpcaddyfile/httptype.go:105 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15).
Data as JSON: /api/errors/f39111a6df19e0ef.
Report an issue: GitHub.
Appendix: source
Thrown at caddyconfig/httpcaddyfile/httptype.go:105
return nil, warnings, err
}
// this will replace both static and user-defined placeholder shorthands
// with actual identifiers used by Caddy
replacer := NewShorthandReplacer()
originalServerBlocks, err = st.extractNamedRoutes(originalServerBlocks, options, &warnings, replacer)
if err != nil {
return nil, warnings, err
}
for _, sb := range originalServerBlocks {
for i := range sb.block.Segments {
replacer.ApplyToSegment(&sb.block.Segments[i])
}
if len(sb.block.Keys) == 0 {
return nil, warnings, fmt.Errorf("server block without any key is global configuration, and if used, it must be first")
}
// extract matcher definitions
matcherDefs := make(map[string]caddy.ModuleMap)
for _, segment := range sb.block.Segments {
if dir := segment.Directive(); strings.HasPrefix(dir, matcherPrefix) {
d := caddyfile.NewDispenser(segment)
err := parseMatcherDefinitions(d, matcherDefs)
if err != nil {
return nil, warnings, err
}
}
}
// evaluate each directive ("segment") in this block
for _, segment := range sb.block.Segments {
dir := segment.Directive()
View on GitHub (pinned to 50e54ee279)