Compare commits

..

2 Commits

Author SHA1 Message Date
f3f5a9c726 caddy: add redirect from old domain 2026-03-10 14:53:35 -04:00
3d4aea8c5b caddy: move to new domain 2026-03-10 14:53:33 -04:00
2 changed files with 46 additions and 3 deletions

View File

@@ -45,7 +45,8 @@ rec {
https = { https = {
certs = services_dir + "/http_certs"; certs = services_dir + "/http_certs";
domain = "gardling.com"; domain = "sigkill.computer";
old_domain = "gardling.com"; # Redirect traffic from old domain
}; };
gitea = { gitea = {

View File

@@ -41,6 +41,9 @@ let
hugo --minify -d $out; hugo --minify -d $out;
''; '';
}; };
newDomain = service_configs.https.domain;
oldDomain = service_configs.https.old_domain;
in in
{ {
imports = [ imports = [
@@ -52,14 +55,53 @@ in
services.caddy = { services.caddy = {
enable = true; enable = true;
email = "titaniumtown@proton.me"; email = "titaniumtown@proton.me";
# Enable on-demand TLS for old domain redirects
# Certs are issued dynamically when subdomains are accessed
globalConfig = ''
on_demand_tls {
ask http://localhost:9123/check
}
'';
# Internal endpoint to validate on-demand TLS requests
# Only allows certs for *.${oldDomain}
extraConfig = ''
http://localhost:9123 {
@allowed expression {query.domain}.endsWith(".${oldDomain}") || {query.domain} == "${oldDomain}" || {query.domain} == "www.${oldDomain}"
respond @allowed 200
respond 403
}
'';
virtualHosts = { virtualHosts = {
${service_configs.https.domain} = { ${newDomain} = {
extraConfig = '' extraConfig = ''
root * ${hugoWebsite} root * ${hugoWebsite}
file_server browse file_server browse
''; '';
serverAliases = [ "www.${service_configs.https.domain}" ]; serverAliases = [ "www.${newDomain}" ];
};
# Redirect old domain (bare + www) to new domain
${oldDomain} = {
extraConfig = ''
redir https://${newDomain}{uri} permanent
'';
serverAliases = [ "www.${oldDomain}" ];
};
# Wildcard redirect for all old domain subdomains
# Uses on-demand TLS - certs issued automatically on first request
"*.${oldDomain}" = {
extraConfig = ''
tls {
on_demand
}
# {labels.2} extracts subdomain from *.gardling.com
redir https://{labels.2}.${newDomain}{uri} permanent
'';
}; };
}; };
}; };