OpenClaw 部署在家里或者内网的话,外网访问是个问题。Cloudflare Tunnel 是目前最优解,免费、稳定、安全。
为什么选 Cloudflare Tunnel
对比了几个方案:
- frp:需要自己有公网服务器,多一个维护点
- ngrok:免费版有限制,域名随机
- Cloudflare Tunnel:免费、自定义域名、自带 DDoS 防护
配置步骤
1. 安装 cloudflared
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared any main' | sudo tee /etc/apt/sources.list.d/cloudflared.list
sudo apt update && sudo apt install cloudflared
2. 创建 Tunnel
cloudflared tunnel login
cloudflared tunnel create openclaw
cloudflared tunnel route dns openclaw ai.yourdomain.com
3. 配置文件
tunnel: your-tunnel-id
credentials-file: /root/.cloudflared/your-tunnel-id.json
ingress:
- hostname: ai.yourdomain.com
service: http://localhost:18789
- service: http_status:404
4. 设为系统服务
sudo cloudflared service install
sudo systemctl enable cloudflared
安全加固
Tunnel 本身是安全的,但建议再加一层 Cloudflare Access:
- 设置邮箱验证或 GitHub OAuth
- 只允许特定邮箱域名访问
- 启用设备策略
这样即使别人知道你的域名,也无法直接访问你的龙虾。
延迟表现
国内访问走 Cloudflare 的话,延迟大概增加 50-100ms,日常使用感知不明显。