Deployment Guide
This guide covers deploying Watch Together using Docker Compose with various reverse proxy options.
Table of Contents
Section titled “Table of Contents”- Prerequisites
- Quick Start
- Deployment Options
- Configuration
- Browser Extension
- Maintenance
- Troubleshooting
Prerequisites
Section titled “Prerequisites”- Docker 24.0+ and Docker Compose v2
- A domain name (for production deployments)
- (Optional) Cloudflare account for Zero Trust authentication
Quick Start
Section titled “Quick Start”# Clone the repositorygit clone https://github.com/rennerdo30/watch-together.gitcd watch-together
# Create environment filecp .env.example .env
# Start all servicesdocker compose up -d --build
# Check statusdocker compose ps
# View logsdocker compose logs -fThe application runs on:
- Port 80: Nginx proxy (main entry point). Published on
127.0.0.1only by default — the Cloudflare tunnel reaches it over the Docker network. SetNGINX_BIND=0.0.0.0(and optionallyNGINX_PORT) to publish it to the LAN.
Internal services (not exposed to host by default):
- Port 3000: Next.js frontend (Docker-internal only)
- Port 8000: FastAPI backend (Docker-internal only)
- Port 4416: bgutil PO token provider (Docker-internal only)
Deployment Options
Section titled “Deployment Options”Option 1: Cloudflare Tunnel (Recommended)
Section titled “Option 1: Cloudflare Tunnel (Recommended)”The most secure method - no open ports required on your server.
1. Create Tunnel
Section titled “1. Create Tunnel”- Go to Cloudflare Zero Trust Dashboard
- Navigate to Networks → Tunnels
- Click Create a tunnel
- Name it (e.g.,
watch-together) - Choose Docker as the environment
- Copy the tunnel token (starts with
ey...)
2. Configure Environment
Section titled “2. Configure Environment”Edit .env:
TUNNEL_TOKEN=eyJhIjoiYWJjMTIz...your_token_here3. Configure Public Hostname
Section titled “3. Configure Public Hostname”In the Cloudflare Dashboard, add a public hostname:
| Setting | Value |
|---|---|
| Public hostname | watch.yourdomain.com |
| Service Type | HTTP |
| URL | watch-together-proxy:80 |
Note: Only one hostname entry is needed. Nginx handles routing internally.
4. Enable Authentication (Strongly Recommended)
Section titled “4. Enable Authentication (Strongly Recommended)”- Go to Access → Applications
- Create a Self-hosted application
- Configure:
- Application domain:
watch.yourdomain.com - Session duration: 24 hours (or preferred)
- Application domain:
- Add an access policy:
- Allow specific emails or email domains
- Example:
*@yourdomain.com
- Copy the application’s Audience (AUD) tag from its Overview page.
Then set both values in .env so the backend verifies identities:
CF_ACCESS_TEAM_DOMAIN=https://yourteam.cloudflareaccess.comCF_ACCESS_AUD=your_application_audience_tagWith these set, the backend validates the signed Cf-Access-Jwt-Assertion
token on every request — checking the signature against your team’s public
keys, the audience, the issuer, and the expiry — and takes the user’s email
from the verified claims.
Why this matters: without these variables the backend falls back to trusting the plain
Cf-Access-Authenticated-User-Emailheader. That header is set by Cloudflare, but anyone who can reach the origin directly can also send it, and identity selects which user’s cookies are used. Set both variables, and keep the origin unreachable except through the tunnel.
Setting them also turns on REQUIRE_AUTHENTICATION, so anonymous WebSocket
and proxy requests are rejected instead of falling back to a guest identity.
Override it explicitly if you want different behaviour.
5. Deploy
Section titled “5. Deploy”docker compose up -d --buildOption 2: Direct Nginx/Traefik
Section titled “Option 2: Direct Nginx/Traefik”For use with your own reverse proxy (Nginx, Traefik, Caddy).
1. Configure the published port
Section titled “1. Configure the published port”Remove or comment out the cloudflared service, then choose where nginx is
published. For a reverse proxy on the same host, the loopback default already
works — just pick the port:
NGINX_PORT=8080 # reachable at 127.0.0.1:8080For a reverse proxy on another host, publish it on all interfaces:
NGINX_BIND=0.0.0.0NGINX_PORT=8080Without Cloudflare Access in front, set up authentication in your own proxy. The backend cannot verify Access assertions that are never issued, so it falls back to trusting the identity header.
2. Configure External Reverse Proxy
Section titled “2. Configure External Reverse Proxy”Nginx Example:
server { listen 443 ssl http2; server_name watch.yourdomain.com;
ssl_certificate /path/to/cert.pem; ssl_certificate_key /path/to/key.pem;
location / { proxy_pass http://localhost:8080; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }
# WebSocket support location /ws { proxy_pass http://localhost:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_read_timeout 86400; }
# Video proxy - extended timeouts location /api/proxy { proxy_pass http://localhost:8080; proxy_http_version 1.1; proxy_buffering off; proxy_read_timeout 600s; proxy_send_timeout 600s; client_max_body_size 0; }}Traefik Example (docker-compose labels):
services: proxy: labels: - "traefik.enable=true" - "traefik.http.routers.watch.rule=Host(`watch.yourdomain.com`)" - "traefik.http.routers.watch.tls.certresolver=letsencrypt" - "traefik.http.services.watch.loadbalancer.server.port=80"Option 3: Local Development
Section titled “Option 3: Local Development”For development without Docker:
# Terminal 1: Backendcd backendpython -m venv venvsource venv/bin/activatepip install -r requirements.txtuvicorn main:app --reload --port 8000
# Terminal 2: Frontendcd frontendnpm cinpm run devSet DEVELOPMENT_MODE=true environment variable to enable ?user= query parameter auth:
DEVELOPMENT_MODE=true uvicorn main:app --reload --port 8000Access at http://localhost:3000 with [email protected] for identity.
Warning: Never enable
DEVELOPMENT_MODEin production. It allows impersonation via query parameter.
Configuration
Section titled “Configuration”Environment Variables
Section titled “Environment Variables”| Variable | Description | Default |
|---|---|---|
TUNNEL_TOKEN |
Cloudflare Tunnel token | (required for CF) |
DATA_DIR |
Data storage directory | ./data |
ALLOWED_ORIGINS |
Comma-separated CORS origins (e.g., https://watch.example.com) |
* (wildcard) |
DEVELOPMENT_MODE |
Enable dev features like query param auth (true/false) |
false |
MAX_CONNECTIONS_PER_ROOM |
Maximum WebSocket connections per room | 50 |
MAX_CONNECTIONS_PER_USER |
Maximum WebSocket connections per user | 10 |
Security Note: In production, always set
ALLOWED_ORIGINSto your specific domain(s). WhenALLOWED_ORIGINSis*, CORS credentials are automatically disabled. TheDEVELOPMENT_MODEflag enables?user=query parameter authentication - never enable in production.
Data Persistence
Section titled “Data Persistence”Data is stored in ./data/ (mapped via Docker volume):
data/├── watchtogether.db # Rooms, format cache, extension tokens, user settings├── cache/ # Segment cache└── yt_dlp_cache/ # yt-dlp download cacheCookies are deliberately absent: the backend holds them in memory only, for
as long as the extension keeps refreshing them (COOKIE_MEMORY_TTL_SECONDS,
30 minutes after the last sync). yt-dlp reads them from a scratch file in a
private directory under /dev/shm (RAM) that exists for one extraction.
Set COOKIE_SCRATCH_DIR to move it. A backend that stored cookies in an
earlier version removes them at startup.
DNS over HTTPS
Section titled “DNS over HTTPS”Every container resolves external names through the dns service, an AdGuard
dnsproxy sidecar that forwards to Cloudflare over HTTPS.
Docker’s embedded DNS still answers container names and only forwards the
rest, so the host’s resolver never sees which hosts the backend fetches
from. The sidecar needs a fixed address inside the stack’s subnet:
| Variable | Description | Default |
|---|---|---|
WT_SUBNET |
Subnet of the compose network | 172.28.0.0/24 |
WT_DNS_IP |
Address of the DNS-over-HTTPS sidecar, inside WT_SUBNET |
172.28.0.53 |
Change both together if the default range collides with another network on
the host. A network that already exists has to be recreated once for the
new subnet to apply: docker compose down && docker compose up -d.
Nginx Configuration
Section titled “Nginx Configuration”The internal Nginx configuration is at nginx/nginx.conf. Key settings:
- Video Proxy: Extended timeouts (600s), disabled buffering
- WebSocket: 24-hour timeout for long sessions
- Streaming: Chunked encoding disabled for compatibility
- Security Headers: CSP, HSTS, Permissions-Policy, X-Content-Type-Options, X-Frame-Options
Container Resource Limits
Section titled “Container Resource Limits”All containers have memory and CPU limits configured via deploy.resources.limits:
| Service | Memory Limit | CPU Limit |
|---|---|---|
| Backend | 1 GB | 2.0 |
| Frontend | 512 MB | 1.0 |
| Proxy (Nginx) | 128 MB | 0.5 |
| Tunnel | 128 MB | 0.5 |
| bgutil | 512 MB | 1.0 |
Browser Extension
Section titled “Browser Extension”The browser extension syncs cookies from YouTube, Twitch and Kick to the server — the only way cookies get there. The server keeps them in memory while the extension keeps refreshing them and drops them 30 minutes after the last sync, so a closed browser’s cookies do not linger.
Installation
Section titled “Installation”From the instance (recommended): open Settings in any room and use the
Chrome / Edge or Firefox button under “Install Extension”. The
backend packages the build from the extension/ folder that docker-compose
mounts read-only at /app/extension (EXTENSION_SOURCE_DIR), so members get
the build matching the server they use. The deploy bundle rsyncs the folder
along with the rest; without it the download answers 503.
- Chrome / Edge: extract
watch-together-chrome.zip, openchrome://extensions, enable “Developer mode”, click “Load unpacked” and select the folder - Firefox: open
about:debugging#/runtime/this-firefox, “Load Temporary Add-on”, pick the ZIP (a temporary add-on lasts until Firefox restarts)
The same packager (backend/services/extension_package.py) builds the
Nightly release from every commit on main,
with a .sha256 beside each archive.
From a checkout (either browser):
- Open Chrome/Firefox and go to
chrome://extensionsorabout:addons - Enable “Developer mode”
- Click “Load unpacked” and select the
extension/folder - Pin the extension for easy access
- Log in to YouTube/Twitch in your browser
- Open your Watch Together instance while signed in, then click the extension icon and connect that site — the extension asks the instance who you are and stores the resulting token locally, on this browser only
- Cookies are synced every ten minutes from then on, on browser start, when you open the instance, and when you return to the browser after a while
The account shown in the popup and in Settings is always the one the backend confirms owns the stored token. If you sign in as somebody else, the extension drops the old connection rather than syncing your cookies to the previous account, and asks you to reconnect.
Maintenance
Section titled “Maintenance”Updating
Section titled “Updating”# Pull latest changesgit pull
# Rebuild and restartdocker compose up -d --buildBackup
Section titled “Backup”# Backup data directorytar -czf backup-$(date +%Y%m%d).tar.gz data/# All servicesdocker compose logs -f
# Specific servicedocker compose logs -f backenddocker compose logs -f frontend
# Last 100 linesdocker compose logs --tail=100 backendRestart Services
Section titled “Restart Services”# Restart alldocker compose restart
# Restart specific servicedocker compose restart backend
# Full rebuilddocker compose down && docker compose up -d --buildTroubleshooting
Section titled “Troubleshooting”Video Not Loading / 403 Forbidden
Section titled “Video Not Loading / 403 Forbidden”Cause: Age-restricted or region-locked content, or a bot check, without a signed-in session.
Fix:
- Install the browser extension (Settings → Install Extension)
- Log in to YouTube in your browser
- Visit Watch Together - cookies sync automatically
- Retry the video
Any member of the room who has the extension is enough for YouTube, Twitch and Kick videos: their session is lent to the room while they are in it, and for 30 minutes after their room tab drops. They have to be signed in to the site in that browser; a signed-out browser’s cookies are not lent.
WebSocket Connection Failed
Section titled “WebSocket Connection Failed”Cause: Reverse proxy not configured for WebSocket upgrade.
Fix: Ensure your proxy passes WebSocket headers:
proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";Video Buffering / HTTP/2 Errors
Section titled “Video Buffering / HTTP/2 Errors”Cause: Streaming issues with HTTP/2 connection reuse.
Fix: The nginx config disables chunked encoding and forces connection close for video proxy. If using Cloudflare, try:
- Disable “HTTP/2 to Origin” in Speed settings
- Or add a Page Rule for
/api/proxy*with Cache Level: Bypass
App Stuck on Loading
Section titled “App Stuck on Loading”Cause: Container not running or build error.
Fix:
# Check container statusdocker compose ps
# Check for errorsdocker compose logs backenddocker compose logs frontend
# Rebuilddocker compose down && docker compose up -d --buildContainer Keeps Restarting
Section titled “Container Keeps Restarting”Cause: Port conflict or missing dependencies.
Fix:
# Check logs for errordocker compose logs backend
# Check if port is in uselsof -i :8000lsof -i :3000No Quality Options Available
Section titled “No Quality Options Available”Cause: Invalid or expired cookies, or none: the server drops cookies 30 minutes after the extension last synced them.
Fix:
- Open the instance with the extension connected — it syncs on arrival
- Or click “Sync now” in the extension popup
- Check backend logs:
docker compose logs backend | grep -i cookie