Behind your own reverse proxy
Run ClipMux without its bundled Caddy, behind a Caddy, nginx or Traefik you already run on ports 80 and 443.
If another proxy already owns ports 80 and 443 on the server, for example a
Caddy or nginx serving other sites, run ClipMux without its own Caddy and
point your proxy at it. deploy/compose.proxy.yml does this: it leaves the
bundled Caddy out and has the setup test reach your public URLs through
your proxy. Your proxy then terminates TLS for both of ClipMux's hostnames.
Before you start
- A server that meets the requirements, with a reverse proxy already serving ports 80 and 443.
- Two DNS names pointing at it, for example
video.example.comandmedia.example.com, and certificates for both from your proxy. opensslandsha256sumon the server.
Don't use the one-line installer on this server. It starts the bundled Caddy on ports 80 and 443: a first install stops because the ports are in use, and an upgrade with it fails to start.
Start ClipMux without Caddy
As root, download a release's compose.yml and check it, then fetch
compose.proxy.yml from the same tag. Set V to the release you want:
mkdir -p /opt/clipmux && cd /opt/clipmux
V=v1.0.0
curl -fsSL -O "https://github.com/visheshgubrani/clipmux/releases/download/$V/SHA256SUMS" \
-O "https://github.com/visheshgubrani/clipmux/releases/download/$V/compose.yml"
sha256sum --check --ignore-missing SHA256SUMS
curl -fsSL -o compose.proxy.yml "https://raw.githubusercontent.com/visheshgubrani/clipmux/$V/deploy/compose.proxy.yml"Write .env, readable only by root:
umask 077
cat > .env <<EOF
CLIPMUX_VERSION=$V
POSTGRES_PASSWORD=$(openssl rand -hex 24)
CLIPMUX_SECRETS_KEY=v1:$(openssl rand -hex 32)
EOFStart it, and read the setup token:
docker compose -f compose.yml -f compose.proxy.yml up -d --wait
docker compose -f compose.yml -f compose.proxy.yml logs app | grep setup_tokenCopy CLIPMUX_SECRETS_KEY from .env somewhere off the server. Without
it, a database backup can't be restored.
The app now listens on 127.0.0.1:8080, and only there. If 8080 is taken,
set CLIPMUX_ADMIN_PORT in .env to another port and run the up
command again.
What your proxy must do
- Serve both hostnames. Forward the public and the media hostname to
127.0.0.1:8080, with TLS for each. - Keep the
Hostheader. ClipMux compares it with the public and media URLs to decide where to redirect and when to send HSTS. - Send
X-Forwarded-ForandX-Forwarded-Proto. ClipMux believes them only fromCLIPMUX_TRUSTED_PROXIES, which compose sets to Docker's private ranges: that is where a proxy on the host connects from. Rate limits and sign-in limits use the client address, and when the public URL ishttps, a request that says it came overhttpis redirected tohttps. A proxy that sendsX-Forwarded-Proto: httpfor HTTPS traffic causes a redirect loop. - Allow large request bodies. With videos stored on this server,
browsers upload 32 MiB parts through
/_storage/on the public hostname, and encoders upload their output there too. - Allow slow responses. Connecting a cloud GPU or Cloudflare, and the setup test, can take up to 5 minutes to answer; encoders hold requests open for up to 45 seconds while they wait for work.
- Hide
/_tls/./_tls/asktells the bundled Caddy which hostnames may get a certificate. The bundled config answers404to it from outside; do the same.
ClipMux uses no WebSockets.
Keep the public hostname off any CDN proxy that challenges API clients,
such as Cloudflare's Browser Integrity Check: it refuses @clipmux/node,
the CLI and encoders, and hides the client's address. Point its DNS
straight at the server ("DNS only" on Cloudflare). Playback goes through the
media hostname, which can be served by
Cloudflare edge delivery later.
The setup test fetches your public and media URLs from inside the app container, through your proxy, so the server must be able to reach its own hostnames.
Example configurations
video.example.com, media.example.com {
respond /_tls/* 404
reverse_proxy 127.0.0.1:8080
}Caddy keeps the Host header, sets X-Forwarded-For and
X-Forwarded-Proto, and limits neither body size nor response time by
default. If your Caddy uses on-demand TLS, point its ask at
http://127.0.0.1:8080/_tls/ask, which approves only the hostnames you set
in ClipMux.
On a small or shared server
Encoding on a server that also runs other services competes with them for
CPU. With compose.proxy.yml, set CLIPMUX_BUILTIN_WORKER=false in .env
and run the up command again: the app then runs no encoder of its own.
Connect Modal,
RunPod or a
PC you own first, so new videos have
somewhere to encode, and the setup test runs there.
Upgrade
Edit CLIPMUX_VERSION in .env, download that release's compose.yml and
compose.proxy.yml as above, then pull and restart:
cd /opt/clipmux
docker compose -f compose.yml -f compose.proxy.yml pull app
docker compose -f compose.yml -f compose.proxy.yml up -d --waitThe app applies database migrations when it starts. See Upgrade and uninstall for what changes between releases and how to roll back.
Restore from a backup
The installer's --restore starts Caddy, so on this server run the same steps
by hand. Put the .env you saved from the old server in /opt/clipmux, with
compose.yml and compose.proxy.yml as above, then bring Postgres up, restore
in a one-off container while nothing else uses the database, and start the rest:
cd /opt/clipmux
docker compose -f compose.yml -f compose.proxy.yml up -d --wait postgres
docker compose -f compose.yml -f compose.proxy.yml run --rm -T --no-deps app admin restore --latest --yes
docker compose -f compose.yml -f compose.proxy.yml up -d --wait
docker compose -f compose.yml -f compose.proxy.yml exec app clipmux admin restore reportThe restore leaves the restore fence up. Read the report, then lift it; see Back up and restore.
Check it works
curl -fsS http://127.0.0.1:8080/readyz
curl -fsSI https://video.example.com/readyzThe first prints ok: the app is up. The second answers 200 through your
proxy once the certificate is in place.
502orconnection refusedfrom the proxy: the app isn't listening yet, or your proxy points at another port thanCLIPMUX_ADMIN_PORT.- A redirect loop: your proxy sends
X-Forwarded-Proto: httpfor HTTPS requests. - Uploads stop at the first part: the proxy's body size limit is below 32 MiB.
- The setup test fails to reach a URL: the server can't reach its own hostnames through the proxy.