Behind a reverse proxy
Run hytte on plain HTTP bound to localhost and let the proxy terminate TLS:
hytte -p 8000 -b 127.0.0.1 --domain chat.example.comWhat the proxy has to do:
- Pass WebSockets on
/ws(theUpgradeandConnectionheaders). The whole chat runs over it. - Keep the
Hostheader. hytte compares the browser’sOriginwithHoston login and on the WebSocket, and refuses requests where they differ. - Send
X-Forwarded-Proto: https, so the session cookie gets theSecureflag. - Allow large request bodies, at least
--max-upload(50 MiB by default), for file uploads. - Don’t time out an idle WebSocket too early. The browser reconnects when the connection drops, but a quiet channel can go minutes without traffic, so use a read timeout of an hour rather than nginx’s default of 60 seconds.
Set --domain to the public hostname. It’s the relying-party ID for passkeys and security keys, and the cookie domain. Without it, passkeys aren’t offered.
Caddy gets the certificate, and handles WebSockets and the headers by itself:
chat.example.com { reverse_proxy 127.0.0.1:8000 request_body { max_size 60MB }}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;
client_max_body_size 60m;
location / { proxy_pass http://127.0.0.1:8000; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_read_timeout 1h; proxy_buffering off; }}
# in the http {} block:map $http_upgrade $connection_upgrade { default upgrade; '' close;}Traefik
Section titled “Traefik”With Docker labels on the hytte service:
labels: - traefik.enable=true - traefik.http.routers.hytte.rule=Host(`chat.example.com`) - traefik.http.routers.hytte.entrypoints=websecure - traefik.http.routers.hytte.tls.certresolver=letsencrypt - traefik.http.services.hytte.loadbalancer.server.port=8000Traefik passes WebSockets and X-Forwarded-Proto by default. Its default request body size is unlimited.
A path prefix?
Section titled “A path prefix?”hytte expects to be served at the root of its hostname (https://chat.example.com/), not under a path like /chat/. Use a subdomain.