借助 cloudflare tunnel 免费公网访问 OpenClaw

0 阅读1分钟

cloudflare tunnel

前提要在 cloudflare 托管一个域名

首先在 cloudflare 配置 tunnel

image.png

具体步骤参考官方文档

配置 openclaw

在 openclaw.json 配置 allowedOrigins,把 cloudflare tunnel 配置的访问地址(假如是https://openclaw.example.com)加上。

{
  "gateway": {
    "port": 18789,
    "controlUi": {
      "enabled": true,
      "allowedOrigins": ["https://openclaw.example.com"]
    },
    ...

设备配对

打开访问地址(如https://openclaw.example.com),会有如下提醒:

image.png

提示需要设备配对。

按提示先运行 openclaw devices list 查看所有设备,结果显示的 Pending (1) 就是刚才被拒绝访问的设备信息

Pending (1)
┌────────────────────────────┬────────┬────────┬────────────┬────────┬────────┐
│ Request                    │ Device │ Role   │ IP         │ Age    │ Flags  │
├────────────────────────────┼────────┼────────┼────────────┼────────┼────────┤
│ xxxxxxxx-88f3-46a9-a406-   │ 14c377 │ operat │            │ just   │        │
│ xxxxxxxxxxxx               │ c4628e │ or     │            │ now    │        │
...
└────────────────────────────┴────────┴────────┴────────────┴────────┴────────┘
Paired (3)
...

运行 openclaw devices approve xxxxxxxx-88f3-46a9-a406-xxxxxxxxxxxx 批准该设备访问。

记得填网关令牌

image.png

再次打开 https://openclaw.example.com,效果如下,完成!

image.png