Skip to content

Set up Cloudflare and HTTPS ​

Bitstream can create your DNS records in Cloudflare and get free Let's Encrypt certificates for the panel. Nodes serve HTTPS with certificate files you put on them.

Everything here lives in the panel under Settings > Domains & HTTPS. The setup wizard already connected Cloudflare, created the panel DNS records and started the panel certificate, so most of it is done.

The one rule to remember ​

Only the panel record may be proxied by Cloudflare (orange cloud). Node records are always DNS only (grey cloud). Video through the Cloudflare proxy breaks the free plan terms and Cloudflare only proxies a few ports. Bitstream enforces this: it never creates a proxied record for a node.

1. Turn on HTTPS on the panel ​

The control serves HTTPS only when you give it a TLS port. Add this line to /opt/bitstream/etc/control.env and restart it:

bash
BS_HTTP_TLS_LISTEN=:443
bash
sudo systemctl restart bs-control

Until a real certificate is issued, the control answers with a self-signed one. ffmpeg and VLC accept it. Browsers and most IPTV apps do not, so get a real certificate (step 4) before you hand out https:// links.

Port 80

Let's Encrypt checks http-01 challenges on port 80, and the control answers them on its plain HTTP port. The installer sets that port to 8080 (BS_HTTP_LISTEN=:8080). So either move it to port 80 (BS_HTTP_LISTEN=:80, then update Panel address in Settings > General), forward port 80 to 8080, or use dns-01 with Cloudflare.

2. Connect Cloudflare (optional) ​

In the Cloudflare dashboard, create an API token with these permissions on your zone:

  • Zone: Read
  • DNS: Edit

In Settings > Domains & HTTPS, paste it in API token and click Save token. Bitstream checks the token before saving it, stores it encrypted, and never shows it again. Afterwards the panel only shows its last characters.

Then pick the Zone and the Panel record, the name that points to this panel, for example tv.example.com.

OptionWhat it does
Proxy the panel through CloudflareOrange cloud for the panel record only.
Keep server records in syncCreates and updates one A/AAAA record for each node's public domain when nodes join or change.
Automate it
bash
curl -s -X PUT $PANEL/cloudflare/token \
  -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"api_token": "your-cloudflare-token"}'

curl -s $PANEL/cloudflare/zones -H "Authorization: Bearer $TOKEN" | jq

curl -s -X PATCH $PANEL/cloudflare \
  -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"zone_id": "<zone id>", "panel_record": "tv.example.com", "panel_proxied": false, "auto_sync": true}'

GET /cloudflare tells you whether a token is set. DELETE /cloudflare/token removes it. The records stay, but they stop updating.

3. Sync the records ​

Click Preview DNS changes. The panel lists what it would create, update or delete, and changes nothing yet. If it looks right, click Apply.

Automate it
bash
curl -s -X POST $PANEL/cloudflare/sync \
  -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"dry_run": true}' | jq

Run it again with "dry_run": false to apply.

4. Get a certificate for the panel ​

Under HTTPS certificates, click Get certificate. Type the Domain and pick how to prove you own it:

ChallengeWhen to use it
http-01The domain points to this machine and port 80 reaches the control (see the tip in step 1).
dns-01Uses your Cloudflare token. Works behind firewalls.

The order runs in the background. The list shows the status: Waiting, Issuing, Valid, Expiring soon or Failed, with the last error. Certificates renew on their own 30 days before they expire.

Automate it
bash
curl -s -X POST $PANEL/certificates \
  -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"domain": "tv.example.com", "challenge": "dns-01"}'

The call answers 202 right away. Follow it with GET /certificates. Renew by hand with POST /certificates/{id}/renew.

5. HTTPS on the nodes ​

When a viewer comes in over https://, the control redirects them to https://<node>:<https port>. So every node that HTTPS viewers can land on needs its own certificate and TLS listener. A node without one makes those viewers fail.

Automatic (Cloudflare token set). Give the node its domains on its Edit page. The Cloudflare sync creates the A and AAAA records. They are DNS only unless you turn on the Cloudflare proxy for that server; most plans do not allow video through the proxy. The control then gets a certificate for each domain with a DNS-01 check, so the node does not need port 80, and sends it to the node over its control channel. Renewed certificates are sent the same way. A wildcard. domain gets a *. record and a wildcard certificate. The server page shows the DNS and certificate state of each domain.

Without Cloudflare. The server page lists the exact records to create at your DNS provider. New installs turn on BS_LISTEN_TLS=:8091 with a self-signed certificate until a real one arrives. You can also bring your own certificate.

Your own certificate. On each node, put the certificate and key in a folder such as /opt/bitstream/data/node/tls/, readable by the bs-node user. Then add these lines to /opt/bitstream/etc/node.env:

bash
BS_LISTEN_TLS=:8091
BS_TLS_CERT=/opt/bitstream/data/node/tls/node.crt
BS_TLS_KEY=/opt/bitstream/data/node/tls/node.key
bash
sudo systemctl restart bs-node

The node reports its HTTPS port to the control on its next heartbeat. If viewers reach it on another port (NAT), set BS_PUBLIC_TLS_PORT too.

For a quick test with only an IP, a self-signed certificate works for ffmpeg and VLC:

bash
sudo mkdir -p /opt/bitstream/data/node/tls
sudo openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes -days 825 \
  -subj "/CN=203.0.113.10" -addext "subjectAltName=IP:203.0.113.10" \
  -keyout /opt/bitstream/data/node/tls/node.key -out /opt/bitstream/data/node/tls/node.crt
sudo chown bs-node /opt/bitstream/data/node/tls/node.key /opt/bitstream/data/node/tls/node.crt

Replace 203.0.113.10 with the node's IP. For browsers and apps, use a real certificate for the node's domain.

Real client IPs behind Cloudflare ​

When the panel record is proxied, every request arrives from a Cloudflare address. Bitstream reads the viewer's real IP from the CF-Connecting-IP header, but only when the request comes from one of Cloudflare's published ranges. Those ranges are on by default in http.cloudflare_proxies, so you do not have to add them anywhere. The header is ignored from any other address, so nobody can fake their IP with it.

For your own reverse proxy, see behind a reverse proxy.

Bitstream documentation