caddyserver/caddy · error

reading default Caddyfile: %v

Error message

reading default Caddyfile: %v

What it means

When no --config is given, Caddy tries the adjacent ./Caddyfile; here that file exists (stat succeeded) but reading it failed with an error other than NotExist — typically EACCES. The distinction matters: a missing default file is silently skipped, an unreadable one is a hard error.

Source

Thrown at cmd/main.go:187

		} else {
			config, err = os.ReadFile(configFile)
			if err != nil {
				return nil, "", "", fmt.Errorf("reading config from file: %v", err)
			}
			logger.Info("using config from file", zap.String("file", configFile))
		}
	} else if adapterName == "" {
		// if the Caddyfile adapter is plugged in, we can try using an
		// adjacent Caddyfile by default
		cfgAdapter = caddyconfig.GetAdapter("caddyfile")
		if cfgAdapter != nil {
			config, err = os.ReadFile("Caddyfile")
			if errors.Is(err, fs.ErrNotExist) {
				// okay, no default Caddyfile; pretend like this never happened
				cfgAdapter = nil
			} else if err != nil {
				// default Caddyfile exists, but error reading it
				return nil, "", "", fmt.Errorf("reading default Caddyfile: %v", err)
			} else {
				// success reading default Caddyfile
				configFile = "Caddyfile"
				logger.Info("using adjacent Caddyfile")
			}
		}
	}

	if yes, err := isCaddyfile(configFile, adapterName); yes {
		adapterName = "caddyfile"
	} else if err != nil {
		return nil, "", "", err
	}

	// load config adapter
	if adapterName != "" {
		cfgAdapter = caddyconfig.GetAdapter(adapterName)
		if cfgAdapter == nil {

View on GitHub (pinned to 50e54ee279)

Solutions

  1. chmod/chown the Caddyfile so the CLI user can read it
  2. Or pass --config explicitly with a readable path
  3. Verify: sudo -u <caddy-user> head -1 ./Caddyfile

Example fix

# before (file owned by root, mode 600, CLI run as caddy user)
caddy run

# after
chmod 644 ./Caddyfile && caddy run
Defensive patterns

Strategy: validation

Validate before calling

# Ensure the default Caddyfile is readable by the CLI user when present:
[ -f Caddyfile ] && [ ! -r Caddyfile ] && { echo "Caddyfile not readable" >&2; exit 1; }

Prevention

When it happens

Trigger: A Caddyfile in the current directory with mode 0600 owned by another user; directory traversal denied; NFS/fuse mounts returning EIO on read.

Common situations: Running the CLI as root while the file is fine, but as a less-privileged user it fails; containers where the Caddyfile is mounted with restrictive ownership.

Related errors


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/f10b94c983e19f2f. Report an issue: GitHub.