Skip to content

CDN & Delivery ​

NukeVideo serves its static CMAF (shared HLS + DASH segments on S3) through proxy nodes you run yourself, under domains you own. The proxies gate access with time-limited tokens, share one cache among themselves and read the packaged output from your S3 bucket. In the admin panel, the domains live under CDN → Domains, the signing keys and access rules under CDN → Delivery, and the Cloudflare token under CDN → Cloudflare.

How a request is served ​

A domain names the whole fleet, not a machine. Every CDN domain resolves to every proxy that is serving, and every proxy serves every domain, so which proxy a viewer reaches is the viewer's resolver's choice. What each proxy does with the request is fixed:

viewer ──https──▶ the proxy the DNS picked        token, IP binding, allowed domains,
                    │                             speed limit, CORS, manifest rewrite,
                    │                             the usage log line
                    │  hot cache (RAM) hit? → answered here
                    ▼  private network, :8090
                  the video's owner on the ring   the fleet's one cached copy, on its disks
                    │  miss
                    ▼
                  S3 bucket  (or the API, for a master manifest)
  1. The API mints the link on the primary domain — https://cdn.example.com/{video}/play/…?__hdnea__=…. The fallbacks wait on standby.
  2. The proxy that receives the request validates the token and applies everything that depends on the viewer. It is the only one that logs the request, so delivery is metered once, by the node whose bandwidth carried it.
  3. It fetches the object from the video's owner: the proxy that a consistent hash of the video's ULID names among the peers. The owner is the only proxy that caches the video on disk and the only one that reads it from the bucket — see One cache for the fleet.

Proxy Nodes ​

Proxy nodes are servers you run and manage from the admin panel (over SSH — see Nodes). Each runs a custom nginx build that:

  • Terminates TLS itself, on port 443, with the certificate the API issued for each CDN domain (Certificates), over HTTP/2 and TLS 1.2 or 1.3. A name it has no certificate for is refused during the handshake rather than answered with the wrong certificate. Port 80 answers the health probe and redirects everything else to https with a 308.
  • Validates Akamai-style stream tokens (HMAC) on incoming requests.
  • Reads the pre-packaged CMAF segments from S3 using AWS authentication. It only ever reads: any method but GET, HEAD and OPTIONS gets a 405.
  • Caches segments once for the whole fleet, on the disk pool of the video's owner, so repeat requests don't hit S3 every time; master manifests are asked of the API, by the owner, which builds them per link, and kept for 30 seconds under the link's options (see Per-link manifests); each viewer still gets their own token written into them, and when the API does not answer the owner serves the packaged manifest from S3 instead. One viewer address can make an owner ask the API for at most 20 uncached manifests a second and 10 at a time, and an owner never holds more than 64 requests open to the API; past any of those the manifest comes from S3 as well. HLS media playlists stay cached for 30 seconds, and downloads never enter a cache (they are whole files, fetched once, and must keep supporting Range resumes): the proxy that receives one fetches it from the bucket itself. See Cache disks.
  • Keeps a small in-memory hot cache of the segments it is asked for most, so a video everybody is watching is served from every node instead of through its owner alone.
  • Embeds the token a manifest was requested with into the segment URLs it rewrites, rather than minting one per manifest, so every request of a playback session carries the same token — the one the API recorded a caller's tracking id against. The token is logged and hashed on the node; nothing downstream sees it. See Requesting a Playback URL.
  • Logs, per request, what the fleet's caches did and what was fetched from the origin to serve it; the nodes page turns that into a hit ratio per node. Origin bytes are recorded under the origin_bytes metric and account 0 — the operator's cost, never a customer's usage.
  • Answers CORS itself: the bucket's CORS rules play no part in self-hosted delivery, and one cached copy of a segment serves every embedding site. Any site may embed unless you set allowed domains.
  • Limits how fast one address can make it fetch unsigned assets from S3: 5 per second, with a burst of 200, and 429 beyond that. Only cache misses count, so a page full of thumbnails already cached is never limited.
  • Keeps serving what it has cached while S3 answers with errors or is unreachable.
  • Verifies the S3 endpoint's TLS certificate unless told not to with VOD_S3_TLS_VERIFY.
  • Resolves the real client IP behind Cloudflare, and behind a reverse proxy of the host's own when one sits in front of the edge.
  • Ships access-log bandwidth to the API through a Vector.dev pipeline. Only responses that delivered content (200, 206) are metered: a refused or failed request names its video in the URL, which needs no token, so counting it would let anyone add usage to a video that is not theirs.

Token validation is configured under CDN → Delivery (token secret, token name, token window, IP binding). The token secret is hexadecimal, in whole bytes; anything else is refused when saved. These are injected into the proxy container at deploy time — see Configuration: Proxy Node Delivery.

CDN domains ​

A CDN domain is a hostname viewers reach the fleet by. Add one under CDN → Domains in the panel (or POST /api/cdn-domains) and the rest follows on its own: its DNS records point at the proxies (DNS), the API asks for its certificate (Certificates) and every proxy starts serving it as soon as the certificate is pushed — no redeploy.

Primary and fallbacks ​

  • The first domain is the primary, and links are minted with the primary. Every other domain is a fallback.
  • A fallback is a warm standby. It already resolves to every proxy, already has its certificate, and shares the cache with the primary — the edges key the cache by path, never by host — so the moment it is promoted it serves cache hits. Nothing hands it out before then.
  • Promoting a fallback is manual: Make primary in the panel, when the primary is lost (a registrar suspension, a blocklist, an expired name). New links use the new primary at once, and any link works on any domain, because the token signs the path and never the host. Links already handed out keep the host they were minted with: they play for as long as that name still resolves to the proxies, and a player whose primary is gone needs a new link — minutes, with short-lived tokens.
  • Deleting the primary promotes the oldest fallback that has a certificate (the oldest of all when none has), so links keep a domain to be minted with while any is left. Deleting a domain removes the records NukeVideo created for it and the edges stop serving it.
  • A domain cannot be renamed. A new name is a new domain, with its own records and its own certificate: add it, wait for its certificate, promote it, then delete the old one.
  • Only a domain with a certificate can be promoted. Links are minted with the primary, and an edge refuses a name it has no certificate for, so the API answers 422 to promoting one without it (on an HTTPS installation). The exception is the first domain, the primary from the moment it is created: playback over it fails until its certificate is issued, usually within a couple of minutes.
  • No domain, or no proxy that is active and not draining, and minting playback or download links answers 503. Thumbnails and storyboards are then served through the API instead.

Use domains of their own ​

Register domains for the CDN alone (examplecdn.com, examplecdn.net) rather than putting it under your product's zone as cdn.example.com:

  • The Cloudflare token can edit the whole zone. Cloudflare scopes DNS permissions per zone, so a token that can write cdn.example.com can also rewrite your site's, your mail's and your API's records — and it sits on the API host. On a zone holding nothing but the CDN, a leaked token can only redirect the CDN.
  • Cookies. Browsers send the cookies of .example.com with every segment request to cdn.example.com, and a page on the CDN's name could set cookies for your site. A separate registrable domain gets none of them.
  • Reputation and blocklists. A name that gets blocked for serving video — by a network filter, a DNS blocklist, a complaint to the registrar — takes only the CDN with it, and a fallback on another TLD and another registrar survives what took the primary down. Spread the fallbacks the same way.

DNS ​

With a Cloudflare API token stored under CDN → Cloudflare, NukeVideo keeps the records of every domain itself: one A or AAAA record per proxy in the serving set, under the domain's exact name.

  • The serving set is every proxy that has been deployed at least once, is active, not draining and answers the health probe. When none answers, it is every deployed, active proxy that is not draining: the probe being wrong for the whole fleet — the API host losing its network, say — is likelier than every edge dying at once, and a name that resolves to nodes that may be down beats one that resolves to nothing.
  • Reconciled, not appended to. The records are brought in line — created, corrected, removed — whenever the set may have changed: a domain deleted or switched between proxied and DNS only, a certificate issued (on a plain-HTTP installation, a domain created), a proxy deployed, drained, switched off, deleted or given a new IP, the probe taking a node out or putting it back. A proxy given a new ipAddress leaves the set until its deploy, or until the probe finds its edge at the new address: the records never point at a host with nothing on it. Saving the Cloudflare settings — a new token, or a new Proxy through Cloudflare default — runs one at once. Every 15 minutes a run happens anyway, which is what repairs a run Cloudflare refused.
  • TTL. DNS-only records carry a 60-second TTL: that is how long a resolver may keep sending viewers to a proxy that left the set. Proxied records take Cloudflare's automatic TTL, the only one it accepts for them.
  • Only its own records. Every record it creates carries the comment Managed by NukeVideo, and nothing without that comment is ever changed or deleted (editing the comment in the dashboard disowns a record). A foreign CNAME on the name, or a foreign A/AAAA pointing anywhere but at one of the proxies, stops that domain with the reason, which the application log carries; delete the record and the next run — within 15 minutes, or right after a proxy deploy — points the domain. A foreign record that already points at one of the proxies is left alone and counted as that proxy's; one pointing at a proxy that is not serving is left alone too, with a line asking you to remove it.
  • What it skips. A domain in no zone the token can see, and a proxy whose ipAddress is a private address, are left for you to point, with a line saying so. With no proxy to point at, the records are left as they are rather than emptied. On an HTTPS installation, a domain without its certificate yet is not pointed at the fleet either — every edge would refuse it — and its records stay as they are until the certificate has been pushed.
  • The zone is not configured: the longest zone the token can see that the hostname ends with is the one used, so domains may live in several zones, and a delegated eu.example.com wins over example.com.
  • The token needs Zone → Zone → Read and Zone → DNS → Edit on the zones of the CDN domains — the same permissions answer the certificates' challenge. It is stored encrypted in the application settings, not in .env, and never shown again.
  • DNS only or proxied. Records are DNS only by default: viewers reach the edge directly, which is already the cache. Proxy through Cloudflare under CDN → Cloudflare makes them proxied for the whole installation, and each domain can say otherwise with its own cloudflareProxied (Cloudflare default, Proxied or DNS only). From Cloudflare's address ranges the edge reads the viewer's address in CF-Connecting-IP, which Cloudflare sets itself, so it still logs, geolocates and binds tokens to the viewer rather than Cloudflare. Before you proxy a domain, check that Cloudflare's terms cover your video traffic, and know that what Cloudflare has cached is answered without reaching the edge, so allowed domains do not apply to it. The edge serves a publicly trusted certificate, so the zone's SSL mode can be Full (strict); the health probe asks each node directly and never goes through Cloudflare.

Without a token, the records are yours to keep: under every domain, one A or AAAA record per proxy, at its public address. CDN → Domains lists the addresses the domains should resolve to (meta.addresses in the API). Nothing takes a dead proxy out of the DNS for you, and the edges cannot get certificates either: HTTPS delivery needs the token.

Certificates ​

The API issues the domains' certificates centrally and hands them to every proxy; the proxies never ask a CA for anything. The ACME client is lego, shipped in the API image, and it solves the DNS-01 challenge through the Cloudflare token under CDN → Cloudflare — so every CDN domain must sit in a Cloudflare zone that token can edit.

Why centrally: a domain resolves to every proxy, so an HTTP challenge sent to the name could land on any of them; a DNS challenge run from each proxy would put a token that can rewrite the zone on every machine facing the internet; and one certificate per domain stays well inside Let's Encrypt's limit of five identical certificates a week, which a fleet of proxies each asking for the same names would exhaust. It also lets a new proxy serve the moment it is deployed.

  • When. A certificate is requested when the domain is created. cdn:certificates runs hourly on the scheduler (a no-op on a plain-HTTP installation) and requests one for every domain that has none, or has less than a third of its lifetime left — 30 days of a 90-day certificate, proportionally less of a shorter one. Without a Cloudflare token it still queues them, so every due domain shows why it gets none, and the command itself fails with a warning: renewals that stop silently are certificates that expire with nobody told. The domain's Issue certificate now action (Renew certificate now once it has one; POST /api/cdn-domains/{id}/certificate) asks at once, due or not, after fixing whatever made the last attempt fail.
  • Where it lives. On the domain, in the database, the private key encrypted. Each issuance runs on the API host's node-ops queue (Horizon on the API host, which holds the token and lego, and waits out a challenge that takes minutes), one at a time; lego's own account and working copies are in storage/app/lego, and losing that directory costs a new ACME account at the next issuance, nothing else.
  • How it reaches the edges. Pushed over SSH, as soon as it is issued, to every deployed proxy that is switched on, draining ones included, followed by nginx -s reload, which keeps every open connection. A proxy that cannot be reached keeps the files it has and is tried again five minutes later; failing that, the daily push to every proxy, or its next deploy, writes them again. Should nginx refuse the new files, the edge keeps serving and the previous files are put back, so a restart does not load them either.
  • When it fails. Each issuance is tried once; the reason — lego's own last lines, which name a token without the permission or a zone it cannot see — is shown on the domain as certificateError until an issuance succeeds, and the hourly run asks again. A failed renewal leaves the current certificate serving, and renewing with a third of the lifetime left gives weeks of retries before anything expires.
  • Which CA. Let's Encrypt, unless ACME_DIRECTORY says otherwise: its staging directory while trying a setup out, so a mistake does not spend the weekly limit (staging certificates are not trusted by browsers, so nothing plays with them), or any other CA that speaks ACME and needs no external account binding.
  • A plain-HTTP installation — a development panel whose APP_URL is http:// — issues nothing, and its edges serve plain HTTP.

One cache for the fleet ​

If every proxy cached what it was asked for, every popular segment would be stored, and fetched from the bucket, once per node. Instead the proxies hash each video's ULID onto a consistent ring of the peers — the same list in the same order on all of them, written by the API — and the proxy the ring names, the video's owner, is the only one that caches it on disk. The others fetch it from the owner over the private network, on port 8090. One copy per video across the fleet, one read from the bucket.

  • Peers are the proxies with a private address that have been deployed and are active and not draining. Health is not asked: a peer that stops answering is skipped by the others request by request, while moving everything it owns onto its neighbours because of three missed probes would turn a fleet's worth of videos cold.
  • The private address is a field of the proxy (privateAddress), an IPv4 address of that host: the deploy refuses, before touching the running edge, an address the host does not have. Redeploy the proxy right after changing it: its edge only listens on the new address once deployed, and the other edges may be handed it before that — until then they find nothing there and hand its videos to the next peer on the ring, cold misses rather than errors. Every proxy deploy hands every edge its current config. Draining or switching a proxy off, or deleting it, pushes the new ring to every edge and reloads it — no redeploy.
  • Adding a proxy moves about 1/(N+1) of the videos onto it. Those arrive cold; the rest stay where they are cached.
  • Draining or switching off a proxy takes it off the ring: its share of the videos moves to its neighbours, cold.
  • When an owner does not answer, the proxy asking tries the next peer on the ring (2-second connect timeout, up to 3 peers), which fetches from the bucket itself: one cold miss instead of a failed segment. A peer that failed is skipped for 10 seconds before it is tried again.
  • The peer port is not for viewers. It is published on the private address alone, and the owner refuses any request without the fleet's peer key — derived from the token secret every proxy already holds, so there is no second secret to hand out or rotate. Behind it is everything in the bucket, unsigned: keep that network to your own machines. A proxy on another token secret — while you redeploy the fleet after changing it — has its requests refused by the others, and serves its share of the ring from the bucket itself until it is redeployed: changing the secret costs cold misses, not errors.
  • A proxy without a private address keeps its own cache and reads the bucket itself, as a ring of one, and is nobody else's owner. A mixed fleet works; it only stores what such a node serves twice.
  • Metering. Only the proxy the viewer reached writes the usage line: node is the proxy that delivered the bytes, and cache and origin say what the owner's cache (or the hot cache) did to get them. The owner logs nothing for its peers, so no byte is counted twice. On the nodes page, a proxy's origin bytes are what its owners fetched from S3 to serve its viewers.

Put the proxies on one private network

Everything a viewer gets from a proxy that does not own the video crosses the private network once — with N proxies, roughly (N−1)/N of what the fleet delivers, less what the hot caches answer. On a vRack, a VLAN or a LAN that traffic is free; between providers, run a VPN (WireGuard, Tailscale) and expect its overhead; over public interfaces it is billed egress, on top of the egress to viewers. Size the private links like the public ports.

The hot cache ​

Each proxy also keeps a small cache in memory — a tmpfs of 5 % of its RAM, between 256 MB and 4 GB, sized by the deploy — of what is hot on that node. An object is stored once the node has been asked for it four times while it still remembered the earlier requests, and goes after 10 minutes without one. That holds the current segments of whatever everybody is watching right now, so a video that goes viral is served from every proxy instead of funnelling through its owner.

It never holds manifests (a master manifest is built per set of options and only the owner knows its cache key), nor anything the node owns itself (that is already on its disks). It is not a second copy of the catalogue, needs no configuration, and starts empty after a restart. X-Cache-Status answers HIT when it served the request.

Network and firewall ​

PortOpen toFor
443/tcpEveryoneViewers, and the API host's health probe
80/tcpEveryoneThe redirect to https, and the probe until the primary domain has its certificate. Everything, on a plain-HTTP installation
8090/tcpThe other proxies, on the private networkThe shared cache. Published on the private address only
22/tcpThe API hostDeploys, and the pushes of certificates, domains and peers

A proxy also needs to reach the S3 endpoint and INTERNAL_API_URL; the API host, Cloudflare's API and the ACME directory. Docker publishes ports with its own firewall rules, ahead of tools like ufw: what keeps 8090 off the internet is that it is bound to the private address, so do not set a public address as a proxy's privateAddress.

One edge per host. The edge holds 80, 443 and the peer port itself, so a deploy refuses — before touching the running edge — when another NukeVideo edge already runs on the host: the other environment's, or a second proxy node on the same machine.

Behind a host's own reverse proxy — a development machine whose Traefik holds port 80 — the edge publishes neither 80 nor 443, speaks plain HTTP and is routed by Docker labels naming every domain. TLS is then that proxy's job, and a domain added later reaches such a host at its next deploy, which rewrites the labels.

When something fails ​

What failsWhat happens
A proxy diesAfter three failed probes (one a minute) it leaves every domain's DNS, and resolvers forget it within the 60-second TTL. The other proxies stop asking it for what it owns at the first refused connection. Viewers who were on it have to reconnect, and once their resolver has dropped it they land on another proxy, where the same link still plays
Every proxy fails the probeThe DNS keeps every active proxy rather than none
A video's owner does not answerThe next peer on the ring fetches from the bucket: a cold miss, not an error
A certificate cannot be issued or renewedThe domain shows certificateError; the current certificate keeps serving and the hourly run retries
A proxy missed a certificate pushFor the primary domain, its health probe fails — the probe connects with the primary's name and checks its certificate as a viewer would — and it leaves the DNS until its files are written again. For any other domain the probe does not notice: that proxy refuses the name at the handshake until a push repairs it — the retry five minutes after a failed one, the daily push, or its next deploy
Cloudflare's API is downThe records stay as they are; the next run repairs them
The primary domain is blockedPromote a fallback: new links use it at once, warm. Links already out on the blocked name fail until the player asks for a new one
No domain, or no active proxyPlayback and download mints answer 503
The API does not answer the ownerMaster manifests come from S3, unpersonalised
S3 does not answerCached objects keep being served, stale if need be

Access rules ​

IP binding ​

By default a playback link plays from anywhere until it expires. Turn on Bind playback links to the viewer's IP and every playback token is signed with the address it was minted for — the ip the request named, or the caller's own — and the edge answers 403 to any request from another address: the manifest and every segment, since they share the token. The address is signed, so it cannot be edited out of the URL.

  • Integrations must mint with the viewer's ip. A backend that mints without it binds every link to its own server's address, and nothing plays.
  • An address change ends the session. A phone moving from Wi-Fi to mobile data, or a dual-stack viewer who reached the API over IPv4 and the edge over IPv6, gets a 403 and has to request a new link. Addresses are compared exactly; IPv6 is not widened to a /64.
  • Downloads are not bound: their tokens carry no address, so a download manager can resume from anywhere.
  • It applies to links minted from then on, with no redeploy. Turning it off does not release links minted while it was on: they stay bound until they expire.

Allowed domains ​

By default any website can use a valid link. List domains under Allowed domains and the edge answers 403 to a request made from a page on any other site, on playback, downloads and assets alike. Leave the list empty for no restriction.

  • example.com matches that exact host, and *.example.com its subdomains but not example.com itself. Ports are ignored.
  • List the site whose page holds the player. If the player sits in an iframe, list the iframe's domain.
  • Redeploy the proxy nodes to apply a change. The list is written into the edge's nginx config when the node deploys.
  • The panel is always allowed, through the hosts in SANCTUM_STATEFUL_DOMAINS (unset, that is APP_URL's host, where the API serves the panel), so it keeps playing from its own origin.
  • How the edge knows the page. It reads Origin, then Referer. A request with neither is refused only when Sec-Fetch-Site says a cross-site page made it, which covers a page that hides its Referer.
  • Your own pages must let the browser send a Referer. On an allowed page with Referrer-Policy: no-referrer or same-origin, a plain <video src>, an <img> or a download link is refused like any other, and so is a link with rel="noreferrer" on any page. Set strict-origin-when-cross-origin, the browser default, or referrerpolicy on the element. Players built on hls.js, dash.js or Shaka are unaffected, since they send Origin.
  • Links from other sites are refused too. A download link clicked on an unlisted site gets a 403, as does a thumbnail in its <img>.
  • List every web origin that plays for you. Hybrid apps count: Capacitor sends capacitor://localhost, which cannot be listed and is refused. A cast receiver page sends its own origin too.
  • A CDN in front answers from its own cache. With a domain proxied through Cloudflare, anything it has cached is served without reaching the edge, so the list does not apply to those requests.
  • It is about browsers. Native apps, curl and other clients outside a browser send none of these headers, or can forge them, and they pass. Links stay protected by their token: keep the token window short, and consider IP binding.
  • The exception is native HLS on iOS. The system media player may fetch the stream without any of these headers, and those requests cannot be told apart from a native app. For iPhones, IP binding is what stops a copied link.
  • A page on file:// sends Origin: null and is refused, unless you allow a null origin.

Allow a null origin ​

A webOS or Tizen app, or a WebView loading local files, is a page on file://. It has no site to name, so its player sends Origin: null and the list refuses it. Turn on Allow a null origin under CDN → Delivery and redeploy the proxy nodes, and the edge serves two more kinds of request:

  • One whose Origin is null, or file:// as some WebViews write it.
  • One for a thumbnail or a storyboard that names no page at all, which is what an <img> in such an app sends. Playback and downloads keep the rule above.

This weakens the list. null identifies nobody: any website sends it from a sandboxed iframe, with no Referer to tell it apart from your app. With the option on, the list stops a site that embeds your links plainly, not one that sets out to get around it. Turn IP binding on with it and keep the token window short, so that a link minted for one viewer is of no use to another site's visitors. The option does nothing while the list is empty.

Released under the MIT License.