summaryrefslogtreecommitdiff
path: root/config/web-server.nix
blob: 24f076364dfe4c9cd1203c96af439968d6eecd0c (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
  mpd_loc = (import ../data/aliases.nix).services.mpd;
  mpdweb_loc = (import ../data/aliases.nix).services.mpdweb;
  pjournal_loc = (import ../data/aliases.nix).services.pjournal;
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/tmp/hls/"
    #  "/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 {
      "tommvo.com" = template // { root = "/storage/srv/tommvo.com"; };
      "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;
          '';
        };
      };
      "git.orbekk.com" = template // {
        locations."/".proxyPass = "http://localhost:11103";
      };
      "nextcloud.orbekk.com" = template;
    };
  };
}