Перейти к содержимому

Reverse proxies and tunnels

By default Squad listens on ports 80 and 443 and gets its own certificate from Let’s Encrypt. In proxy mode it serves plain HTTP on port 8080, and your reverse proxy or tunnel handles HTTPS in front of it. Voice and video skip the proxy, and always connect to the machine on TCP port 7881 and UDP port 7882.

Set FLUXER_EDGE_MODE=proxy in fluxer.env, and publish 127.0.0.1:8080:8080 in place of ports 80 and 443, the same as behind your own proxy with Docker. Your proxy then connects to Squad on 127.0.0.1:8080.

In proxy mode, Squad trusts the visitor address in X-Forwarded-For from private addresses. To trust only your proxy, set FLUXER_EDGE_TRUSTED_PROXIES to its address. When people open Squad on a port other than 443, set FLUXER_PUBLIC_PORT to that port.

Inside a container, 127.0.0.1 is the container itself, not the machine. When Traefik, nginx or Caddy runs in Docker and connects to Squad on 127.0.0.1, it fails with a 502 and “connection refused” in its log.

With rexctl, bind Squad to the address of the Docker bridge, which containers can connect to, and allow connections from private addresses. rexctl then writes that address into the configs in the proxy folder.

Окно терминала
rexctl proxy on --bind 172.17.0.1:8080 --proxy-from private

When the proxy container uses its own network, use the gateway address of that network in place of 172.17.0.1. docker network inspect <network> shows it.

When you run Squad yourself with docker compose, put Squad and the proxy on one Docker network and point the proxy at http://fluxer:8080. Squad then needs no published port for the proxy.

Each config below sends chat.example.com to Squad on 127.0.0.1:8080. Replace both with your own. They are the same configs rexctl proxy config writes.

Caddyfile
chat.example.com {
reverse_proxy 127.0.0.1:8080
}

Caddy gets the certificate, forwards WebSockets and sets X-Forwarded-For by itself.

  • Serve HTTPS with TLS 1.2 and 1.3, because video in the mobile apps needs TLS 1.2.
  • Pass WebSockets, paths and query strings through unchanged.
  • Set X-Forwarded-For to the request’s address, and drop any value the visitor sent.
  • Accept request bodies of at least 512 MiB, to match the upload limits. Keep idle connections open for an hour, or at least 120 seconds.
  • Add no Content-Security-Policy header, because Squad sends its own.
  • Use /_health for health checks.

Without a proxy, Squad can also serve HTTPS with a certificate you already have in place of one from Let’s Encrypt. Set FLUXER_EDGE_TLS to the certificate file, with the full chain, and the key file. Squad looks for a file name without a folder in /etc/fluxer/certs.

Put both files in a certs folder next to fluxer.env, then add this line to fluxer.env.

fluxer.env
FLUXER_EDGE_TLS=fullchain.pem privkey.pem

Then mount the folder with -v ./certs:/etc/fluxer/certs:ro on the docker run line, or with - ./certs:/etc/fluxer/certs:ro under volumes in compose.yaml. Squad runs as user ID 65532 in the container, so the files need to belong to that user ID.

Окно терминала
sudo chown 65532:65532 certs/*.pem && sudo chmod 0400 certs/privkey.pem

To renew, replace both files and reload Squad with the command for how it runs. Squad then serves the new certificate without a restart.

How Squad runsReload
Compose filedocker compose kill -s HUP fluxer
docker rundocker kill -s HUP fluxer
Linux by handsystemctl reload fluxerd

With certbot on a systemd install, a deploy hook does this after each renewal.

sudo tee /etc/letsencrypt/renewal-hooks/deploy/fluxer > /dev/null <<'EOF'
#!/bin/sh
install -o root -g fluxer -m 0640 "$RENEWED_LINEAGE/fullchain.pem" "$RENEWED_LINEAGE/privkey.pem" /etc/fluxer/certs/
systemctl reload fluxerd
EOF
sudo chmod 0755 /etc/letsencrypt/renewal-hooks/deploy/fluxer

When your domain points at Cloudflare’s proxy and Squad serves HTTPS itself, change these settings in the Cloudflare dashboard.

  • Turn Rocket Loader off, because the web app shows a blank page with it on.
  • Don’t let a Cache Rule store HTML pages, or people get an old web app after upgrades.
  • Turn Bot Fight Mode off and add no challenges for /api/, /gateway or /livekit/. The desktop and mobile apps can’t solve them.
  • Set the SSL/TLS encryption mode to “Full (strict)” in the dashboard.

Cloudflare keeps serving cached media after someone deletes it. To purge it right away, make an API token with the Zone Cache Purge permission and set FLUXER_CACHE_PURGE_ADAPTER=http, FLUXER_CACHE_PURGE_HTTP_ENDPOINT to https://api.cloudflare.com/client/v4/zones/<zone id>/purge_cache and FLUXER_CACHE_PURGE_HTTP_TOKEN to the token.

A tunnel can’t forward call audio and video. Without ports 7881 and 7882 open on the machine, calls need a TURN server on a machine with a public address, such as coturn on a small VPS, or a voice server on such a machine. Add a TURN server with the FLUXER_LIVEKIT_TURN_SERVERS setting or with rexctl.

Окно терминала
rexctl voice turn add --host turn.example.com --secret-file secret.txt

When calls still don’t connect with a TURN server, check that the router lets the voice server connect out to the relay, or open ports 7881 and 7882.