With your own domain

Serve the Messaging Server at its own address over HTTPS: DNS, a reverse proxy such as Caddy or nginx, and the TRUST_PROXY, SESSION_COOKIE_SECURE and PUBLIC_URL settings.

3 min read

With a domain of your own, the Messaging Server runs behind a reverse proxy like any web app, and people add it in the app by its address, such as chat.example.com. No Flaq Connect and no relay are involved. This guide assumes you have downloaded and configured the server as in Install the server.

1. Point the domain at the machine#

Give the name you chose, such as chat.example.com, a DNS record pointing at the machine the proxy runs on. The proxy needs TCP port 443 open to the internet.

2. Put a reverse proxy in front#

The server listens on 127.0.0.1:8105 on the host. The proxy takes HTTPS on port 443 and passes it on there. It must:

  • pass WebSockets through, at /api/v1/ws, which is how the apps get messages live;
  • allow large uploads, up to the largest file you let people send;
  • allow long-lived connections.

Caddy#

Caddy gets and renews the certificate by itself, and passes WebSockets and large uploads by default. Its whole configuration, in /etc/caddy/Caddyfile:

chat.example.com {
    reverse_proxy 127.0.0.1:8105
}

nginx#

nginx needs WebSockets, long connections and large uploads turned on:

location / {
    proxy_pass http://127.0.0.1:8105;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_read_timeout 1h;
    client_max_body_size 1100m;
}

with this in the http block:

map $http_upgrade $connection_upgrade { default upgrade; '' close; }

Cloudflare Tunnel and Traefik#

Cloudflare Tunnel and Traefik work too. Cloudflare Tunnel passes WebSockets and large uploads by default.

3. Tell the server about the proxy#

Add three settings to .env, next to docker-compose.yml:

TRUST_PROXY=1
SESSION_COOKIE_SECURE=1
PUBLIC_URL=https://chat.example.com
Setting What it does
TRUST_PROXY How many reverse proxies are in front, usually 1. The server then takes each client's address and scheme from the X-Forwarded-* headers the proxy adds
SESSION_COOKIE_SECURE 1 marks the admin console's cookies Secure, so the browser sends them only over HTTPS
PUBLIC_URL The server's HTTPS address. Anyone who opens the server over plain HTTP, at its LAN address or port included, is sent there with the same path, and the browser stays on HTTPS from then on

Set TRUST_PROXY to the real number

Setting TRUST_PROXY higher than the number of proxies actually in front lets a client forge its address. Leaving it at 0 behind a proxy makes every client share the proxy's address, so the limits on sign-in attempts and sign-ups count everyone together.

PUBLIC_URL also gives your server's accounts their handles: the host of its address is their home, so someone on this server is @ana@chat.example.com. See Accounts across servers.

4. Start it and open it#

docker compose up -d

Then open https://chat.example.com. The first visit opens the setup wizard; go on with the setup wizard in Install the server. People then add the server in the app by typing chat.example.com.

Changing .env later takes effect after the same command, docker compose up -d.

Turnstile on this address#

If you turn on Cloudflare Turnstile for the admin console's sign-in, list the hostname the server is reached on, chat.example.com, in the Turnstile widget. A widget that no longer lists it makes the sign-in challenge fail for everyone. See The admin console.

Adding Connect later#

A server with its own domain doesn't need Flaq Connect. You can still list it on a Connect later, from the admin console's Flaq Connect page, for an invite link or a short name to share. See At home with Connect.

If something is wrong#

  • The app keeps saying it's reconnecting. The proxy isn't passing WebSockets through.
  • "Flaq can only encrypt on a page opened over HTTPS." The console was opened at an http:// address other than localhost. Open the HTTPS address; with PUBLIC_URL set, plain-HTTP visits go there by themselves.
  • "Too many attempts" for everyone at once. TRUST_PROXY isn't set, so every client shares the proxy's address.

More in Troubleshooting.