summaryrefslogtreecommitdiff
path: root/hosts/cloud/proxy/dav.nix
blob: d3bf7fbac7dc4be0a5e4d3b2ea264f1e195e2cd9 (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
{ ... }:
{
  services.nginx.upstreams.radicale = {
    servers = {
      "10.89.88.12:5232" = { };
      "[fd31:185d:722f::12]:5232" = { };
    };
  };

  services.nginx.virtualHosts."dav.oxapentane.com" = {
    forceSSL = true;
    enableACME = true;
    locations."/oauth2/" = {
      proxyPass = "http://10.89.88.11:4180/";
      extraConfig = ''
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Auth-Request-Redirect $scheme://$host$request_uri;
      '';
    };
    locations."/oauth2/auth" = {
      proxyPass = "http://10.89.88.11:4180";
      extraConfig = ''
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Uri $request_uri;
        proxy_set_header Content-Length "";
        proxy_pass_request_body off;
      '';
    };
    locations."/" = {
      proxyPass = "http://radicale/";
      extraConfig = ''
        auth_request /oauth2/auth;
        error_page 401 =403 /oauth2/sign_in;

        auth_request_set $user $upstream_http_x_auth_request_user;

        auth_request_set $auth_cookie $upstream_http_set_cookie;
        # add_header Set-Cookie $auth_cookie;

        proxy_set_header X-Remote-User $user;
        proxy_set_header X-User $user;
        proxy_set_header X-Real-IP $remote_addr;

      '';
    };
  };
}