Infini-OPTIPLEX: simplify web setup

This commit is contained in:
Infinidoge 2024-04-26 06:18:42 -04:00
parent 6fc8b69fff
commit 522df23288
Signed by: Infinidoge
SSH key fingerprint: SHA256:VEv3zmkBzcYYle6/37h+BbOyNDbGy/o8SHh7fcs9RbQ

View file

@ -1,9 +1,40 @@
{ config, pkgs, ... }: { config, pkgs, lib, ... }:
let let
inherit (config.common.nginx) ssl ssl-optional; 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 in
{ {
services.nginx.virtualHosts = { services.nginx.virtualHosts = websites // redirects // {
"blahaj.inx.moe" = ssl-optional // { "blahaj.inx.moe" = ssl-optional // {
locations."/" = { locations."/" = {
tryFiles = "/Blahaj.png =404"; tryFiles = "/Blahaj.png =404";
@ -21,25 +52,13 @@ in
"test.inx.moe" = ssl // { "test.inx.moe" = ssl // {
locations."/" = { locations."/" = {
root = "/srv/web/inx.moe"; root = "/srv/web/inx.moe";
tryFiles = "$uri $uri.html $uri/ =404"; inherit tryFiles;
extraConfig = '' extraConfig = 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; }
'';
}; };
}; };
"ponder.inx.moe" = ssl // { "ponder.inx.moe" = ssl // {
locations."/".root = pkgs.ponder; locations."/".root = pkgs.ponder;
}; };
"nitter.inx.moe" = ssl // {
globalRedirect = "twitter.com";
};
}; };
} }