caddyserver/caddy · error

invalid port '%s': %v

Error message

invalid port '%s': %v

What it means

Error "invalid port '%s': %v" thrown in caddyserver/caddy.

Source

Thrown at caddyconfig/httpcaddyfile/addresses.go:414

		host, port, err := net.SplitHostPort(hostSplit[0])
		if err != nil {
			host, port, err = net.SplitHostPort(hostSplit[0] + ":")
			if err != nil {
				host = hostSplit[0]
			}
		}
		a.Host = host
		a.Port = port
	}
	if len(hostSplit) == 2 {
		// all that remains is the path
		a.Path = "/" + hostSplit[1]
	}

	// make sure port is valid
	if a.Port != "" {
		if portNum, err := strconv.Atoi(a.Port); err != nil {
			return Address{}, fmt.Errorf("invalid port '%s': %v", a.Port, err)
		} else if portNum < 0 || portNum > 65535 {
			return Address{}, fmt.Errorf("port %d is out of range", portNum)
		}
	}

	return a, nil
}

// String returns a human-readable form of a. It will
// be a cleaned-up and filled-out URL string.
func (a Address) String() string {
	if a.Host == "" && a.Port == "" {
		return ""
	}
	scheme := a.Scheme
	if scheme == "" {
		if a.Port == strconv.Itoa(certmagic.HTTPSPort) {
			scheme = "https"

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Use a numeric port between 1 and 65535 in the address.
  2. Remove non-numeric characters or service names from the port portion of the address.

When it happens

Trigger: Thrown at caddyconfig/httpcaddyfile/addresses.go:414 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/11946225be485756. Report an issue: GitHub.