summaryrefslogtreecommitdiff
path: root/config/web-server.nix
blob: 48f8f0177de76d7a780fcd66843be2e786693b80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
{ config, lib, pkgs, ... }:
let
  aliases = import ../data/aliases.nix;
  keycloak_loc = aliases.services.keycloak;
in {
  security.acme.acceptTerms = true;
  security.acme.defaults.email = "kj@orbekk.com";

  networking.firewall.allowedTCPPorts = [ 80 443 ];

  systemd.services.nginx.serviceConfig = {
    # I used to store web files in /home.
    # ProtectHome = "read-only";
    ReadWritePaths = [
      "/storage/srv/kj.orbekk.com/dav/"
    ];
    UMask = lib.mkForce "0007";
  };

  services.nginx = {
    enable = true;
    package = pkgs.nginxStable.override {
      modules = with pkgs.nginxModules; [ dav rtmp ];
    };
    recommendedProxySettings = true;
    appendHttpConfig = ''
      # Extra mime types.
      types {
        text/plain  org;
      }
      # This is a workaround to deal with closed connections on
      # large downloads.
      proxy_buffering off;
      charset utf-8;
      tcp_nopush on;
      aio on;
      directio 512;
    '';
    virtualHosts = let
      template = {
        enableACME = true;
        forceSSL = true;
      };
    in {
      "orbekk.no" = template // { root = "/storage/srv/orbekk.com"; };
      "orbekk.com" = template // { root = "/storage/srv/orbekk.com"; };
      "wifi.orbekk.com" = template // {
        root = "/storage/srv/wifi.orbekk.com";
      };
      "wifi.orbekk.no" = template // { root = "/storage/srv/wifi.orbekk.com"; };
      "kj.orbekk.com" = template // {
        root = "/storage/srv/kj.orbekk.com";
        extraConfig = ''
          autoindex on;
        '';
        locations."/dav" = {
          root = "/storage/srv/kj.orbekk.com";
          extraConfig = ''
            auth_basic webdav;
            dav_ext_methods PROPFIND OPTIONS;
            # htpasswd -c /opt/secret/nginx-webdav.htpasswd
            auth_basic_user_file "/opt/secret/nginx-webdav.htpasswd";
            dav_methods put delete mkcol copy move;
            dav_access user:rw group:rw all:rw;
            create_full_put_path on;
            autoindex on;
          '';
        };
      };
      "auth.orbekk.com" = template // {
        locations."/".proxyPass = "http://localhost:${toString keycloak_loc.http-port}";
      };
      "git.orbekk.com" = template // {
        locations."/".proxyPass = "http://localhost:11103";
      };
      "nextcloud.orbekk.com" = template;
    };
  };
}