返回社区案例

【最近实战】解决 OpenClaw Gateway Web 控制台因非安全上下文导致设备身份创建失败的问题

发布时间:2026/5/28浏览量:390

我通过 Wisdom SSH 连接到远程服务器,尝试在浏览器中访问 OpenClaw Gateway 的 Web 控制台时,页面报错:

此页面通过普通 HTTP 运行,因此浏览器无法创建 Gateway 期望的设备身份。使用 HTTPS/Tailscale Serve,或在 Gateway 主机上打开 http://127.0.0.1:***。如需本地仅令牌兼容,设置 gateway.controlUi.allowInsecureAuth: true。避免为远程 HTTP 访问禁用设备认证。原始错误:control ui requires device identity (use HTTPS or localhost secure context)

这个错误的核心原因是浏览器安全策略:在非安全上下文(非 HTTPS、非 localhost)中,浏览器会禁用 Web Crypto API(SubtleCrypto),导致 Gateway 无法在客户端生成设备身份密钥对。即使服务端配置了 allowInsecureAuth: true,也只能放宽服务端的验证逻辑,无法绕过浏览器层面的硬限制。

我通过 Wisdom SSH 执行命令,首先检查 Gateway 是否正常运行:

curl -sk https://127.0.0.1:*** 2>&1 | head -20

返回为空,说明 Gateway 没有在本地监听 HTTPS。接着检查进程状态:

ps aux | grep -i openclaw | grep -v grep

输出显示 Gateway 进程正在运行:

/usr/bin/node /usr/lib/node_modules/openclaw/dist/index.js gateway --port ***

确认进程存活后,我查看了 Gateway 的配置文件 /root/***/openclaw.json,关键配置如下:

  • gateway.port: ***
  • gateway.bind: "lan"
  • gateway.controlUi.allowInsecureAuth: true(已启用,但如前所述无法解决浏览器层面的限制)
  • gateway.controlUi.allowedOrigins: 包含 http://***.***.***.***:*** 和 https://***.***.***.***
  • gateway.auth.mode: "token"
  • gateway.tailscale.mode: "off"

配置中 allowInsecureAuth 已经设为 true,但问题依旧,这印证了问题出在浏览器端而非服务端。

继续排查,我发现服务器上运行着 nginx:

ps aux | grep -i nginx

进一步查找 nginx 配置文件:

find /etc/nginx -name "*.conf" -type f

找到了 /etc/nginx/conf.d/openclaw.conf,内容显示已经配置了一个 HTTPS 反向代理:

server {
    listen *** ssl;
    server_name ***.***.***.***;

    ssl_certificate /etc/nginx/ssl/openclaw.crt;
    ssl_certificate_key /etc/nginx/ssl/openclaw.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    location / {
        proxy_pass http://127.0.0.1:***;
        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;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout ***;
    }
}

这个 nginx 配置将 *** 端口的 HTTPS 请求反向代理到本地 Gateway 的 *** 端口,使用自签名证书。我验证了 HTTPS 访问是否正常:

curl -sk https://***.***.***.***/ 2>&1 | head -30

返回了完整的 OpenClaw Control 页面 HTML,确认 HTTPS 反向代理工作正常。同时也验证了本地 HTTP 访问:

curl -s http://127.0.0.1:*** 2>&1 | head -5

同样返回正常页面。

至此问题定位完成:解决方案已经就绪,只需改用 HTTPS 访问即可。我给出了三个方案:

  1. 直接使用 HTTPS 访问(推荐,已配置好):访问 https://***.***.***.***,首次访问时点击「高级」→「继续前往」忽略自签名证书警告。可带上 token 跳过手动输入:https://***.***.***.***/#token=***

  2. SSH 端口转发(备选,浏览器通过 localhost 访问天然具备安全上下文):ssh -L ***:127.0.0.1:*** root@***.***.***.***,然后访问 http://127.0.0.1:***

  3. Tailscale Serve(备选,自动提供 Let's Encrypt 证书):openclaw gateway --tailscale-mode serve

整个排查过程通过 Wisdom SSH 完成,从检查进程状态、读取配置文件、分析 nginx 反向代理配置,到验证各端点可访问性,逐步定位到浏览器安全上下文的根因,并确认了已存在的 HTTPS 反向代理就是最直接的解决方案。

本文由用户分享,展示了Wisdom SSH在AI运维中的实际应用

推荐社区案例

点击阅读真实AI运维案例