{"record":{"id":"f39111a6df19e0ef","repo":"caddyserver/caddy","slug":"server-block-without-any-key-is-global-configurati","errorCode":null,"errorMessage":"server block without any key is global configuration, and if used, it must be first","messagePattern":"server block without any key is global configuration, and if used, it must be first","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"caddyconfig/httpcaddyfile/httptype.go","lineNumber":105,"sourceCode":"\t\treturn nil, warnings, err\n\t}\n\n\t// this will replace both static and user-defined placeholder shorthands\n\t// with actual identifiers used by Caddy\n\treplacer := NewShorthandReplacer()\n\n\toriginalServerBlocks, err = st.extractNamedRoutes(originalServerBlocks, options, &warnings, replacer)\n\tif err != nil {\n\t\treturn nil, warnings, err\n\t}\n\n\tfor _, sb := range originalServerBlocks {\n\t\tfor i := range sb.block.Segments {\n\t\t\treplacer.ApplyToSegment(&sb.block.Segments[i])\n\t\t}\n\n\t\tif len(sb.block.Keys) == 0 {\n\t\t\treturn nil, warnings, fmt.Errorf(\"server block without any key is global configuration, and if used, it must be first\")\n\t\t}\n\n\t\t// extract matcher definitions\n\t\tmatcherDefs := make(map[string]caddy.ModuleMap)\n\t\tfor _, segment := range sb.block.Segments {\n\t\t\tif dir := segment.Directive(); strings.HasPrefix(dir, matcherPrefix) {\n\t\t\t\td := caddyfile.NewDispenser(segment)\n\t\t\t\terr := parseMatcherDefinitions(d, matcherDefs)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, warnings, err\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// evaluate each directive (\"segment\") in this block\n\t\tfor _, segment := range sb.block.Segments {\n\t\t\tdir := segment.Directive()\n","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/caddyconfig/httpcaddyfile/httptype.go#L87-L123","documentation":"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.","triggerScenarios":"Thrown at caddyconfig/httpcaddyfile/httptype.go:105 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Move the global options block (the block with no keys) to the very top of the Caddyfile, before any site blocks."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","contentChangedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}