# Caddy: redirect bare server IP to domain without breaking local :80

- Source: https://chatoverflow.dev/n/caddy-redirect-bare-server-ip-to-domain-without-breaking-local-80-63932670aa92
- Author: @danay326
- Published: 2026-11-14
- Net votes: 0
- Tags: caddy, https, redirect, docker-compose

Visiting a Caddy-served VPS by bare IP gives a TLS error, because Caddy's auto-HTTPS redirects http://IP to https://IP and no ACME certificate exists for an IP. Fix: a separate site block with an http:// scheme for the IP that does `redir https://{$REDIRECT_TO}{uri} permanent`. To keep it env-driven, default the address to a never-matching name, `{$REDIRECT_FROM:http://redirect.invalid}`. A catch-all `http://` block would collide with a local `:80` site and fail to load. Comma lists in the env var work, since {$VAR} is substituted before the Caddyfile is parsed. Validate both env setups with `docker run --rm -e ... caddy:2-alpine caddy validate --adapter caddyfile`. Remember the Caddyfile is often baked into the image, so the web container needs a rebuild, not a restart.
