From 054f98fc340d67189ab91c771cb5bb8d77018bf1 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Wed, 14 Feb 2024 11:15:46 +0100 Subject: [PATCH] feat(redirections): Add more precise redirection for retired websites, to make analytics relevant --- machines/web01/redirections.nix | 39 ++++++++++++++----------------- machines/web01/static/default.nix | 2 ++ 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/machines/web01/redirections.nix b/machines/web01/redirections.nix index 1da0855..b6189d5 100644 --- a/machines/web01/redirections.nix +++ b/machines/web01/redirections.nix @@ -9,7 +9,11 @@ let builtins.map (name: { inherit name; - value.to = retired_host; + value = { + enableACME = true; + forceSSL = true; + locations."/".return = "301 https://${retired_host}/${name}"; + }; }) hosts ); @@ -17,6 +21,15 @@ let mkSub = domain: builtins.map (s: "${s}.${domain}"); mkSubs = attrs: builtins.concatLists (builtins.attrValues (builtins.mapAttrs mkSub attrs)); + mkRedirection = + _: + { to }: + { + globalRedirect = to; + enableACME = true; + forceSSL = true; + }; + redirections = { "calendrier.eleves.ens.fr".to = "calendrier.dgnum.eu"; "docs.beta.rz.ens.wtf".to = "pads.dgnum.eu"; @@ -26,7 +39,7 @@ let "rdv.dgnum.eu".to = "meet.dgnum.eu"; "www.bda.ens.fr".to = "bda.ens.fr"; "bda.wp.dgnum.eu".to = "bda.ens.fr"; - } // (mkRetired retired); + }; retired = mkSubs { "ens.fr" = [ @@ -53,23 +66,7 @@ let }; in { - services.nginx.virtualHosts = - { - ${retired_host}.default = true; - } - // (builtins.mapAttrs - ( - _: - { - to, - ssl ? true, - }: - { - globalRedirect = to; - enableACME = ssl; - forceSSL = ssl; - } - ) - redirections - ); + services.nginx.virtualHosts = { + ${retired_host}.default = true; + } // (builtins.mapAttrs mkRedirection redirections) // (mkRetired retired); } diff --git a/machines/web01/static/default.nix b/machines/web01/static/default.nix index 3454b5d..6ff068f 100644 --- a/machines/web01/static/default.nix +++ b/machines/web01/static/default.nix @@ -23,6 +23,8 @@ in services.nginx.virtualHosts = recursiveUpdate (builtins.mapAttrs mkVhost websites) { "eleves.dgnum.eu".locations."/".tryFiles = "$uri $uri/index.html /fr/$uri /en/$uri /fr/index.html"; + "retired.dgnum.eu".locations."/".tryFiles = "/index.html =404"; + "simi.normalesup.eu" = { enableACME = true; forceSSL = true;