Reverse proxy and HTTPS
For a domain name with HTTPS, put a reverse proxy in front of OwnTube. Send /media/* to the gateway and everything else to the web app.
Without a proxy the web app forwards /media/* to the gateway itself. That works, but every video byte then passes through Next.js. With a proxy the gateway serves media directly.
1. Expose the gateway
Section titled “1. Expose the gateway”The default compose file only publishes the web app. If the proxy runs in Docker on the same network, use the service names (app:3000, gateway:8080). If it runs on the host, publish the gateway on localhost:
services: gateway: ports: - "127.0.0.1:8080:8080"2. Tell the web app its address
Section titled “2. Tell the web app its address”Add the public URL, so sign-in redirects and links in podcast feeds use it:
AUTH_URL=https://tube.example.orgAUTH_TRUST_HOST=trueAdd both to the environment: block of the app service as well, then run docker compose up -d.
3. Configure the proxy
Section titled “3. Configure the proxy”tube.example.org { encode zstd gzip { match { not path /media/* } } handle /media/* { reverse_proxy 127.0.0.1:8080 { flush_interval -1 } } handle { reverse_proxy 127.0.0.1:3000 }}Caddy gets a certificate on its own and enables HTTP/3. Keep HTTP/3 on: Safari aborts a media request on every seek, and over HTTP/3 those aborts don’t disturb other requests on the same connection.
server { listen 443 ssl; http2 on; server_name tube.example.org; # ssl_certificate …; ssl_certificate_key …;
location /media/ { proxy_pass http://127.0.0.1:8080; proxy_buffering off; proxy_request_buffering off; proxy_read_timeout 1h; proxy_set_header Host $host; }
location / { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }}Turn buffering off for /media/. With buffering on, seeking stalls.
4. Check it
Section titled “4. Check it”curl -I https://tube.example.org/Play a video with the browser’s network panel open. Segment requests go to /media/… and return 200 or 206.