乐于分享
好东西不私藏

OpenClaw 通过 ngrok 远程访问指南

OpenClaw 通过 ngrok 远程访问指南
一、前置安装
1. 安装 ngrok
1brew install ngrok
2. 注册 ngrok 账号并配置 token(只需一次)

注册地址: https://dashboard.ngrok.com/signup

获取 token: https://dashboard.ngrok.com/get-started/your-authtoken

1ngrok config add-authtoken <你的token>
二、配置 OpenClaw

配置文件路径: ~/.openclaw/openclaw.json

gateway 部分需要以下配置:

1{
2  "gateway": {
3    "port": 18789,
4    "mode": "local",
5    "bind": "lan",
6    "trustedProxies": ["127.0.0.1/32"],
7    "controlUi": {
8      "allowedOrigins": ["*"]
9    },
10    "auth": {
11      "mode": "token",
12      "token": "你的token"
13    }
14  }
15}

关键配置说明:

bind: "lan" — 允许局域网访问(默认 loopback 只允许本地)

trustedProxies — 信任 ngrok 代理转发的请求头,否则会被当作不可信连接

allowedOrigins: ["*"] — 允许跨域访问

三、启动服务
1. 启动 OpenClaw 网关
1openclaw gateway stop
2openclaw gateway run --bind lan

或者用 service 方式:

1openclaw gateway start
2. 启动 ngrok 转发 18789 端口
1ngrok http 18789

ngrok 会输出一个公网 URL,类似: https://xxxx-xxxx.ngrok-free.dev

四、手机/远程浏览器连接

1. 打开 ngrok 给的公网 URL,会看到 OpenClaw 仪表盘

2. 填写连接信息:

  - WebSocket URL: wss://xxxx-xxxx.ngrok-free.dev   - 网关令牌: 你的 gateway token   - 点击"连接"

3. 首次连接会提示 "pairing required",需要在电脑上批准设备

五、设备配对审批(关键步骤)

每个新设备/浏览器首次连接需要在电脑上批准,之后同一设备不再需要。

1. 查看待批准设备列表
1openclaw devices list

会显示 Pending 列表,包含 Request ID 和设备信息。

2. 批准设备
1openclaw devices approve <Request ID>

例如:

1openclaw devices approve 89ee7a64-56c2-472d-856e-1db30ffa62db

批准后手机上重新点"连接"即可。

其他设备管理命令:

openclaw devices list — 查看所有设备

openclaw devices reject — 拒绝配对请求

openclaw devices remove — 移除已配对设备

openclaw devices revoke — 撤销设备 token

六、注意事项

○ ngrok 免费版每次启动会分配不同的 URL,需要重新在手机上填写

○ 每个新设备只需批准一次,配对信息会保存

○ ngrok 需要保持运行,关掉后远程就无法访问了

○ 如果网关启动报错 "gateway already running",先执行 openclaw gateway stop

如果觉得有收获,欢迎关注「知了星AI」,一起看 AI 能把内容创作带到哪里。