|
| 1 | +# cloudflared install for `zhub-server --public-tunnel` |
| 2 | + |
| 3 | +`zhub-server` can spawn an ephemeral Cloudflare Tunnel and print a `*.trycloudflare.com` URL when started with `--public-tunnel`. This requires the `cloudflared` binary on your PATH. **No Cloudflare account needed** for ephemeral tunnels. |
| 4 | + |
| 5 | +Verified live on 2026-05-09 — round-tripped a chat completion through `https://*.trycloudflare.com → hub → publisher → response` end-to-end. The install path below is exactly what was used. |
| 6 | + |
| 7 | +## Install |
| 8 | + |
| 9 | +### Static binary (any Linux, no apt needed) |
| 10 | + |
| 11 | +This is what works inside proot, Termux, or any minimal Linux environment: |
| 12 | + |
| 13 | +```bash |
| 14 | +ARCH=$(uname -m) |
| 15 | +case "$ARCH" in |
| 16 | + x86_64) BIN=cloudflared-linux-amd64 ;; |
| 17 | + aarch64) BIN=cloudflared-linux-arm64 ;; |
| 18 | + armv7l) BIN=cloudflared-linux-arm ;; |
| 19 | + *) echo "unsupported $ARCH"; exit 1 ;; |
| 20 | +esac |
| 21 | +sudo curl -fsSL \ |
| 22 | + "https://github.com/cloudflare/cloudflared/releases/latest/download/$BIN" \ |
| 23 | + -o /usr/local/bin/cloudflared |
| 24 | +sudo chmod +x /usr/local/bin/cloudflared |
| 25 | +``` |
| 26 | + |
| 27 | +### Debian / Ubuntu (with apt) |
| 28 | + |
| 29 | +```bash |
| 30 | +ARCH=$(dpkg --print-architecture) |
| 31 | +curl -fsSL "https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${ARCH}.deb" -o /tmp/cf.deb |
| 32 | +sudo dpkg -i /tmp/cf.deb |
| 33 | +``` |
| 34 | + |
| 35 | +### macOS |
| 36 | + |
| 37 | +```bash |
| 38 | +brew install cloudflared |
| 39 | +``` |
| 40 | + |
| 41 | +### Verify |
| 42 | + |
| 43 | +```bash |
| 44 | +cloudflared --version |
| 45 | +# cloudflared version YYYY.MM.D ... |
| 46 | +``` |
| 47 | + |
| 48 | +## Use |
| 49 | + |
| 50 | +```bash |
| 51 | +zhub-server --port 8080 --public-tunnel |
| 52 | +``` |
| 53 | + |
| 54 | +In about 5 seconds: |
| 55 | + |
| 56 | +``` |
| 57 | +INFO zhub.tunnel: starting cloudflared: /usr/local/bin/cloudflared tunnel --url http://localhost:8080 --no-autoupdate |
| 58 | +INFO zhub.tunnel: tunnel up at https://random-words.trycloudflare.com |
| 59 | +INFO zhub.persistence: persistence opened at zhub.db |
| 60 | +INFO: Started server process [...] |
| 61 | +INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit) |
| 62 | +``` |
| 63 | + |
| 64 | +Anything you publish locally (`hub_url=ws://127.0.0.1:8080`) is now reachable from the world via that URL. |
| 65 | + |
| 66 | +```bash |
| 67 | +curl https://random-words.trycloudflare.com/<your-ai>/v1/chat/completions \ |
| 68 | + -H "Authorization: Bearer zk_..." \ |
| 69 | + -d '{"messages":[{"role":"user","content":"hi"}]}' |
| 70 | +``` |
| 71 | + |
| 72 | +## Caveats |
| 73 | + |
| 74 | +- **The URL is ephemeral.** Different on every restart of `cloudflared`. For a stable URL, configure a named tunnel in the Cloudflare dashboard and front the hub behind it the normal way; that's outside zhub's scope but well-documented at https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/. |
| 75 | +- **Cloudflare quickstart tunnels are intended for testing.** Don't share the URL with the public internet at scale; use a named tunnel + Access for that. |
| 76 | +- **Both processes must stay alive.** Killing `cloudflared` alone leaves the hub running but unreachable; killing the hub alone leaves cloudflared 502'ing requests. `zhub-server --public-tunnel` ties their lifecycles — Ctrl+C on the hub also tears down cloudflared. |
| 77 | + |
| 78 | +## Troubleshooting |
| 79 | + |
| 80 | +| Symptom | Cause | Fix | |
| 81 | +|---|---|---| |
| 82 | +| `cloudflared not found on PATH` | binary not installed | re-run install above | |
| 83 | +| `did not produce a public URL within 30s` | egress blocked or proxy interfering | run `cloudflared tunnel --url http://localhost:8080` manually to see CF's actual error | |
| 84 | +| URL changes on every restart | ephemeral tunnels rotate | use a named tunnel for stability | |
| 85 | +| `502` from public URL | hub crashed but cloudflared still up | check `zhub-server` log; `pkill cloudflared` then restart | |
| 86 | +| Tunnel works briefly then hangs | inactive idle timeout from CF edge | reconnect; for production traffic use a named tunnel | |
| 87 | +| `proot` exit 144 immediately on launch | shell sub-process bookkeeping in proot — process actually fine | use `nohup ... &` + `disown`, verify via `curl <url>/healthz` | |
0 commit comments