/ self-hosting / tls ← self-hosting

TLS and reverse proxies

The server speaks plain HTTP on loopback and expects something in front of it to end TLS. The shipped stack uses Caddy; this page is what that file does, the equivalents for nginx and Traefik, and the one flag that has to be right either way.

Caddy, which is what ships

deploy/Caddyfile is nine lines:

{$YAP_DOMAIN} {
	encode zstd gzip
	header {
		Strict-Transport-Security "max-age=31536000"
		-Server
	}
	# Don't keep request logs: they would hold IPs and paths.
	log {
		output discard
	}
	reverse_proxy yap:8080
}

Caddy gets and renews the certificate on its own. Keep the log block discarded: a proxy access log is the one file that would turn a server that stores no addresses into one that stores every address and path.

nginx

Not shipped, and not tested by this project — the shape you need is a WebSocket-aware proxy with no access log:

server {
  listen 443 ssl;
  http2 on;
  server_name chat.example.com;

  ssl_certificate     /etc/letsencrypt/live/chat.example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/chat.example.com/privkey.pem;
  add_header Strict-Transport-Security "max-age=31536000" always;

  client_max_body_size 4m;   # uploads are capped at 3 MB by the server

  location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;      # /gateway is a WebSocket
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_read_timeout 3600s;                    # a silent idle socket is normal
  }
}

Leave access_log off. Without the two Upgrade lines the REST half works and /gateway hangs, which looks like a server bug.

Traefik

Labels on the yap service, with Traefik on the same compose network:

services:
  yap:
    labels:
      - traefik.enable=true
      - traefik.http.routers.yap.rule=Host(`chat.example.com`)
      - traefik.http.routers.yap.entrypoints=websecure
      - traefik.http.routers.yap.tls.certresolver=le
      - traefik.http.services.yap.loadbalancer.server.port=8080

Traefik's access log is off by default; leave it off.

--trust-proxy, and why it is not optional

Behind a proxy every request arrives from 127.0.0.1, so the per-address sign-up cap would see one address and allow exactly two accounts on the whole server. --trust-proxy tells the server to read the first X-Forwarded-For entry instead. The Docker image sets it because Caddy is the only thing that can reach the container.

Terminating somewhere else

You can put Cloudflare or another CDN in front, but then that party terminates TLS and sees the traffic, which removes most of the reason to run your own box. The official API is the one place where this is not a contradiction: it is a Cloudflare Worker, so Cloudflare is the server rather than a middleman.

Updated . Part of hosting and self-hosting.