Use curl -k --resolve bjorn.now:443:127.0.0.1 https://bjorn.now when testing an HTTPS site locally using Caddy, instead of curl -k -H "Host: bjorn.now" https://localhost, because Caddy relies on SNI and refuses the connection if it doesn’t know which host you’re trying to connect to.
This seems to be a security decision to avoid leaking which certificates (and therefore sites) it hosts by not providing a default (can’t find a source and it’s what the search previews give me). Which my old nginx setup did.
The cryptic error message from cURL, which I didn’t find anything obvious online about:
And I debugged this together with Claude by enabling debug logging in Caddy ({ debug } at the top level in the Caddyfile) which gave me this output when I called it using cURL:
The culprit was the "ServerName":"", and I’m guessing also "sni": "", so if you need to validate and see that as well then that’s likely the problem. 🙂
This jogs my memory, back in the olden times, we would need a unique IP address for each HTTPS site because we couldn’t multi-host, and SNI solved that problem.
Importantly, SNI doesn’t encrypt the host name and it’s still sent in plaintext to the server.