加入我们的 Telegram 社群 (clawdbotCN) 学习分享和了解更多 →
网关
远程访问

远程访问

如何从外部网络访问您的 Clawdbot 网关。

访问方式

1. SSH 端口转发

最简单的方式,无需公开端口:

# 在本地机器上
ssh -L 18789:localhost:18789 user@gateway-host

然后在本地访问 http://localhost:18789

2. Tailscale

推荐用于安全的点对点连接:

# 在网关主机上
tailscale serve --bg 18789

或使用 Tailscale Funnel(公开访问):

tailscale funnel 18789

详见 Tailscale 集成

3. 反向代理

使用 Nginx 或 Caddy 作为反向代理:

Nginx 配置

server {
    listen 443 ssl http2;
    server_name gateway.example.com;
 
    ssl_certificate /path/to/cert.pem;
    ssl_certificate_key /path/to/key.pem;
 
    location / {
        proxy_pass http://127.0.0.1:18789;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Caddy 配置

gateway.example.com {
    reverse_proxy localhost:18789
}

4. VPS 部署

在云服务器上直接运行网关:

网关配置

远程访问时的推荐配置:

{
  gateway: {
    mode: "local",
    bind: "loopback",  // 保持 loopback,通过隧道/代理访问
    port: 18789,
    auth: {
      mode: "token",
      token: "your-secure-token"  // 必须设置!
    }
  }
}

如果必须绑定到所有接口:

{
  gateway: {
    bind: "all",  // 危险:确保有防火墙保护
    auth: {
      mode: "token",
      token: "your-secure-token"
    }
  }
}

安全注意事项

  1. 始终使用认证:设置 gateway.auth.token
  2. 使用 HTTPS:通过反向代理或 Tailscale 提供 TLS
  3. 限制 IP 访问:使用防火墙规则
  4. 定期更换令牌:定期更新认证令牌

CLI 远程连接

配置 CLI 连接到远程网关:

# 运行引导向导,选择"远程"模式
clawdbot onboard
 
# 或手动配置
clawdbot configure --gateway-url wss://gateway.example.com --gateway-token YOUR_TOKEN

故障排除

连接超时

  1. 检查网关是否运行:clawdbot gateway status
  2. 检查防火墙规则
  3. 验证 SSH 隧道或 VPN 连接

WebSocket 连接失败

  1. 检查反向代理的 WebSocket 配置
  2. 确保 UpgradeConnection headers 正确传递

认证失败

  1. 检查令牌是否正确
  2. 确保令牌在请求头或查询参数中

相关文档