aboutsummaryrefslogtreecommitdiff
path: root/hosts/enode/caddy.nix
blob: afb3b69699526450469934a5d95812fa07818869 (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
{ config, ... }:
let
  headscale = {
    domain = config.services.headscale.address;
    port = config.services.headscale.port;
  };

  simpleProxies = {
    "sorre.xyz" = "tower.sorre.internal:7291";
    "git.sorre.xyz" = "tower.sorre.internal:8721";
    "idm.sorre.xyz" = "tower.sorre.internal:8443";
  };

  simpleProxyVirtualHosts = builtins.mapAttrs (domain: upstream: {
    extraConfig = ''
      reverse_proxy ${upstream} {
        header_up True-Client-IP {remote_host}
        header_up X-Real-IP {remote_host}
      }
    '';
  }) simpleProxies;
in
{
  services.caddy = {
    enable = true;
    openFirewall = true;
    virtualHosts = {
      "http://headscale.sorre.xyz".extraConfig = ''
        handle /generate_204 {
          respond 204
        }

        handle * {
          redir https://{host}{uri}
        }
      '';
      "headscale.sorre.xyz".extraConfig = ''
        reverse_proxy ${headscale.domain}:${toString headscale.port} {
          header_up True-Client-IP {remote_host}
          header_up X-Real-IP {remote_host}
        }
      '';
    }
    // simpleProxyVirtualHosts;
  };
}