Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Reverse proxies and TLS

The server speaks plain HTTP on port 8080 and expects something in front of it to terminate TLS. Any reverse proxy works if it does five things.

What the proxy must do

  1. Serve public_url’s host over HTTPS, with a certificate browsers and phones trust. The apps refuse plain http except for localhost, and passkeys need HTTPS on a domain name.
  2. Pass WebSockets on /api/v1/sync, and let them stay open for hours. That connection is how the apps sync; it sends a ping now and then, but an idle timeout of a minute will keep cutting it.
  3. Accept large request bodies: at least [attachments] max_bytes (100 MiB by default), for attachments and meeting recordings.
  4. Not buffer streamed responses. Ask streams its answers as server-sent events, for up to [ask] timeout_secs (300 s).
  5. Not put a login in front of Drusite. Sign-in is Drusite’s own, and the apps can’t follow a proxy’s forward-auth or SSO redirect. Use OIDC to sign in through your identity provider instead.

Pass every path through. Agents in particular need /mcp, /oauth/… and /.well-known/oauth-protected-resource.

Caddy

notes.example.com {
	request_body {
		max_size 110MB
	}
	reverse_proxy localhost:8080 {
		flush_interval -1
	}
}

Caddy gets and renews the certificate itself and passes WebSockets as they are. flush_interval -1 sends streamed answers as they come.

nginx

server {
    listen 443 ssl;
    http2 on;
    server_name notes.example.com;
    ssl_certificate     /etc/letsencrypt/live/notes.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/notes.example.com/privkey.pem;

    client_max_body_size 110m;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_buffering off;
        proxy_read_timeout 1h;
        proxy_send_timeout 1h;
    }
}

# In the http block:
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

On Kubernetes with ingress-nginx, the same as annotations:

nginx.ingress.kubernetes.io/proxy-body-size: 110m
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-buffering: "off"

Traefik

With Docker labels on the drusite service:

labels:
  - traefik.enable=true
  - traefik.http.routers.drusite.rule=Host(`notes.example.com`)
  - traefik.http.routers.drusite.entrypoints=websecure
  - traefik.http.routers.drusite.tls.certresolver=letsencrypt
  - traefik.http.routers.drusite.middlewares=drusite-body
  - traefik.http.middlewares.drusite-body.buffering.maxRequestBodyBytes=115343360
  - traefik.http.services.drusite.loadbalancer.server.port=8080

Traefik passes WebSockets and streams responses without more settings. Its entry points’ respondingTimeouts.readTimeout defaults to 60 s in Traefik 3; raise it if uploads of big files over slow connections fail:

entryPoints:
  websecure:
    address: ":443"
    transport:
      respondingTimeouts:
        readTimeout: 600s

Cloudflare Tunnel and other tunnels

Tunnels work: point one at http://localhost:8080 (or http://drusite:8080 inside Compose). Mind the tunnel’s own upload limit, which may be lower than max_bytes, and don’t add Cloudflare Access in front of the app’s host, for the same reason as any proxy login.

Published pages on a host of their own

Publish to web can serve published pages from a second host, say pages.example.com, on a listener of its own ([publish] listen, port 8443). Route only that host to that port, and set [publish] client_ip_header to the header your proxy sets (x-forwarded-for), so its per-reader limits see readers rather than the proxy. The server can also serve that host’s TLS itself, with no proxy: see Publish to web.

Check it

curl -s https://notes.example.com/readyz
curl -s https://notes.example.com/api/v1/version

Then sign in from an app. If sync connects and then drops every minute or so, the proxy’s WebSocket timeout is too short; if attachments fail at a certain size, its body limit is too low. More in Troubleshooting.