diff --git a/hosts/Infini-OPTIPLEX/web.nix b/hosts/Infini-OPTIPLEX/web.nix index bf77d72..6ae3185 100644 --- a/hosts/Infini-OPTIPLEX/web.nix +++ b/hosts/Infini-OPTIPLEX/web.nix @@ -1,9 +1,40 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: let inherit (config.common.nginx) ssl ssl-optional; + + tryFiles = "$uri $uri.html $uri/ =404"; + websiteConfig = '' + error_page 403 /403.html; + error_page 404 /404.html; + + location ^~ /.well-known { allow all; } + + location = /template.html { deny all; } + location ~* "\.(nix|lock)" { deny all; } + location ~ "/\..+" { deny all; } + ''; + + mkWebsite = name: ssl // { + locations."/" = { + root = "/srv/web/${name}"; + inherit tryFiles; + extraConfig = websiteConfig; + }; + }; + + mkRedirect = from: to: ssl-optional // { globalRedirect = to; }; + + websites = lib.genAttrs [ + "inx.moe" + "stickers.inx.moe" + ] mkWebsite; + + redirects = lib.mapAttrs mkRedirect { + "nitter.inx.moe" = "twitter.com"; + }; in { - services.nginx.virtualHosts = { + services.nginx.virtualHosts = websites // redirects // { "blahaj.inx.moe" = ssl-optional // { locations."/" = { tryFiles = "/Blahaj.png =404"; @@ -21,25 +52,13 @@ in "test.inx.moe" = ssl // { locations."/" = { root = "/srv/web/inx.moe"; - tryFiles = "$uri $uri.html $uri/ =404"; - extraConfig = '' - error_page 403 /403.html; - error_page 404 /404.html; - - location ^~ /.well-known { allow all; } - - location = /template.html { deny all; } - location ~* "\.(nix|lock)" { deny all; } - location ~ "/\..+" { deny all; } - ''; + inherit tryFiles; + extraConfig = websiteConfig; }; }; "ponder.inx.moe" = ssl // { locations."/".root = pkgs.ponder; }; - "nitter.inx.moe" = ssl // { - globalRedirect = "twitter.com"; - }; }; }