Home

infra @c89b314420e0430a59182deb2062737e3e45ea48 - refs - log -
-
https://git.jolheiser.com/infra.git
dragonwell flake
infra / dragonwell / caddy.nix
- raw -
  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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
{ pkgs, ... }:
let
  modules = import ./go.nix;
in
{
  services.caddy = {
    enable = true;
    virtualHosts = {
      "jolheiser.com" = {
        extraConfig = ''
          handle_path /.well-known/webfinger {
            header Content-Type application/jrd+json
            respond ${
              builtins.toJSON {
                subject = "acct:john@jolheiser.com";
                links = [
                  {
                    rel = "http://openid.net/specs/connect/1.0/issuer";
                    href = "https://id.jolheiser.com";
                  }
                ];
              }
            }
          }
          handle_path /bennet* {
            root * ${pkgs.jolheiser.bennet}
            file_server
          }
          handle /resume* {
            root * ${pkgs.jolheiser.resume}
            rewrite /resume /resume.pdf
            file_server
          }
          handle {
            root * ${pkgs.jolheiser.website}
            file_server
          }
        '';
        serverAliases = [ "www.jolheiser.com" ];
      };
      "blog.jolheiser.com" = {
        extraConfig = ''
          root * ${pkgs.jolheiser.blog}
          file_server
        '';
      };
      "go.jolheiser.com" = {
        extraConfig = ''
          header Content-Type text/html
          ${modules}
          respond /* `<html><head>
            <meta name="go-import" content="go.jolheiser.com{path} git https://git.jolheiser.com{path}.git">
            <meta http-equiv="refresh" content="3; url=https://pkg.go.dev/go.jolheiser.com{path}" />
            </head><body>
            Redirecting to <a href="https://pkg.go.dev/go.jolheiser.com{path}">https://pkg.go.dev/go.jolheiser.com{path}</a>
            </body></html>`
        '';
      };
      "git.jolheiser.com".extraConfig = ''
        reverse_proxy localhost:8449
      '';
      "pr.jolheiser.com".extraConfig = ''
        reverse_proxy localhost:7449
      '';
      "id.jolheiser.com".extraConfig = ''
        reverse_proxy localhost:2884
      '';
      "recipes.jolheiser.com".extraConfig = ''
        reverse_proxy localhost:3663
      '';
      "irc.jolheiser.com".extraConfig = ''
        reverse_proxy localhost:7658
      '';
      "dnd.jolheiser.com".extraConfig = ''
        reverse_proxy localhost:30000
      '';
      "pds.jolheiser.com".extraConfig = ''
        reverse_proxy localhost:2759
      '';
      "memos.jolheiser.com".extraConfig = ''
        reverse_proxy localhost:6366
      '';
      "oa2p.jolheiser.com".extraConfig = ''
        reverse_proxy localhost:6227
      '';
      "wiki.jolheiser.com".extraConfig = ''
        	handle /oauth2/* {
        		reverse_proxy localhost:6227 {
        			header_up X-Real-IP {remote_host}
        			header_up X-Forwarded-Uri {uri}
        		}
        	}

        	handle {
        		forward_auth localhost:6227 {
        			uri /oauth2/auth

        			header_up X-Real-IP {remote_host}

        			@error status 401
        			handle_response @error {
        				redir * /oauth2/sign_in?rd={scheme}://{host}{uri}
        			}
        		}

        		reverse_proxy localhost:9454
        	}
      '';
      "budget.jolheiser.com".extraConfig = ''
        handle_path /static/* {
          root * ${pkgs.jolheiser.mint}/lib/mint/static/
          file_server
        }
        reverse_proxy localhost:6468
      '';
      "dev.jolheiser.com".extraConfig = ''
        reverse_proxy localhost:3389
        handle_errors 502 503 504 {
          respond "No active tunnel"
        }
      '';
    };
  };
}