add frontend redirect hosts

This commit is contained in:
Yisroel Baum 2026-08-17 23:52:24 +03:00
parent 2f8d666060
commit 4cdbebe7f9
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 55 additions and 40 deletions

View file

@ -417,7 +417,10 @@ Example host configuration:
config.sops.secrets."borg-private-key".path;
};
frontend.hostName = "rabbigerzi.com";
frontend = {
hostName = "rabbigerzi.com";
redirectHostNames = [ "www.rabbigerzi.com" ];
};
backend = {
hostName = "api.rabbigerzi.com";

View file

@ -120,6 +120,12 @@ in
description = "Frontend nginx virtual host name.";
};
redirectHostNames = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = "Frontend host names that redirect to the canonical host.";
};
publicUrl = lib.mkOption {
type = lib.types.str;
default = "https://${cfg.frontend.hostName}";
@ -403,7 +409,13 @@ in
recommendedProxySettings = lib.mkDefault true;
recommendedTlsSettings = lib.mkDefault true;
virtualHosts = {
virtualHosts =
lib.genAttrs cfg.frontend.redirectHostNames (redirectHostName: {
enableACME = true;
forceSSL = true;
globalRedirect = cfg.frontend.hostName;
})
// {
${cfg.frontend.hostName} = lib.mkMerge [
cfg.frontend.nginx
{