nixos-module: fix caddy Host-header matching for 127.0.0.1/[::1]

Caddy strictly matches vhosts on the exact Host header, unlike nginx
where a single vhost acts as the default regardless of Host. With
hostname = "localhost" (the local-dev default), visiting the VM via
http://127.0.0.1:PORT instead of http://localhost:PORT sent a Host
header matching no vhost, and Caddy silently returned an empty 200 OK
- a genuine white screen with no error anywhere (not in the console,
not in the network tab).

Adds serverAliases for 127.0.0.1:80 and [::1]:80 to the caddy vhost
when hostname is "localhost", so all three ways of reaching the local
VM resolve to the same site block. Verified directly: before this
fix, curl with `Host: 127.0.0.1` got an empty response while `Host:
localhost` got the full app shell; after, all three (localhost,
127.0.0.1, [::1]) return the same 200 response.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-26 14:37:12 -04:00
co-authored by Claude Sonnet 5
parent a71ccc87bb
commit d7fea37e25
2 changed files with 12 additions and 0 deletions
+8
View File
@@ -557,6 +557,14 @@ in
cfg.proxy.caddyConfig
{
hostName = lib.mkForce proto_hostname;
# Caddy matches vhosts on the exact Host header, unlike nginx's single-vhost-is-default
# behavior. For local dev, accept requests to 127.0.0.1/[::1] too - otherwise visiting
# via the IP literal instead of "localhost" hits no vhost and gets an empty 200 response
# (a silent white screen, no error anywhere).
serverAliases = lib.mkIf (cfg.hostname == "localhost") [
"127.0.0.1:80"
"[::1]:80"
];
extraConfig = ''
encode zstd gzip
root ${invoiceninja}/public