From ce06f43476863da90dc60dcee606d2b6c5a89a8e Mon Sep 17 00:00:00 2001 From: sefidel Date: Wed, 29 Mar 2023 20:54:19 +0900 Subject: project: initial commit --- modules/services/userweb.nix | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 modules/services/userweb.nix (limited to 'modules/services/userweb.nix') diff --git a/modules/services/userweb.nix b/modules/services/userweb.nix new file mode 100644 index 0000000..1477f59 --- /dev/null +++ b/modules/services/userweb.nix @@ -0,0 +1,36 @@ +{ config, lib, ... }: + +with lib; +let + cfg = config.modules.services.userweb; +in +{ + options.modules.services.userweb = { + enable = mkEnableOption "serve user web contents"; + domain = mkOption { type = types.str; }; + }; + + config = mkIf cfg.enable { + modules.services.nginx.enable = true; + + services.nginx.virtualHosts.${cfg.domain} = { + forceSSL = true; + useACMEHost = cfg.domain; + + serverName = "${cfg.domain} www.${cfg.domain}"; + + locations."~ ^/(~u/)(?[\w-]+)(?/.*)?$" = { + alias = "/home/$user/public_html$user_uri"; + index = "index.html index.php index.cgi index.py index.sh index.pl index.lua"; + + extraConfig = '' + error_page 404 /~$user/404.html; + ''; + }; + + extraConfig = '' + error_log /var/log/nginx/${cfg.domain}-error.log crit; + ''; + }; + }; +} -- cgit 1.4.1