caddyserver/caddy · error

%s:%d: parsed '%s' as a site address, but it is a known dire

Error message

%s:%d: parsed '%s' as a site address, but it is a known directive; directives must appear in a site block

What it means

Error "%s:%d: parsed '%s' as a site address, but it is a known directive; directives must appear in a site block" thrown in caddyserver/caddy.

Source

Thrown at caddyconfig/httpcaddyfile/httptype.go:74

// Setup makes a config from the tokens.
func (st ServerType) Setup(
	inputServerBlocks []caddyfile.ServerBlock,
	options map[string]any,
) (*caddy.Config, []caddyconfig.Warning, error) {
	var warnings []caddyconfig.Warning
	gc := counter{new(int)}
	state := make(map[string]any)

	// load all the server blocks and associate them with a "pile" of config values
	originalServerBlocks := make([]serverBlock, 0, len(inputServerBlocks))
	for _, sblock := range inputServerBlocks {
		for j, k := range sblock.Keys {
			if j == 0 && strings.HasPrefix(k.Text, "@") {
				return nil, warnings, fmt.Errorf("%s:%d: cannot define a matcher outside of a site block: '%s'", k.File, k.Line, k.Text)
			}
			if _, ok := registeredDirectives[k.Text]; ok {
				return nil, warnings, fmt.Errorf("%s:%d: parsed '%s' as a site address, but it is a known directive; directives must appear in a site block", k.File, k.Line, k.Text)
			}
		}
		originalServerBlocks = append(originalServerBlocks, serverBlock{
			block: sblock,
			pile:  make(map[string][]ConfigValue),
		})
	}

	// apply any global options
	var err error
	originalServerBlocks, err = st.evaluateGlobalOptionsBlock(originalServerBlocks, options)
	if err != nil {
		return nil, warnings, err
	}

	// this will replace both static and user-defined placeholder shorthands
	// with actual identifiers used by Caddy
	replacer := NewShorthandReplacer()

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Place the directive inside a site block instead of using it as a site address.
  2. If you intended a site address, rename it so it does not collide with a known directive name.

When it happens

Trigger: Thrown at caddyconfig/httpcaddyfile/httptype.go:74 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/5b6c7d5545589aa2. Report an issue: GitHub.