A self-hosted AI agent behind a per-user reverse proxy
说明与用途
用户可通过单击按钮启动 OpenClaw,UI 在新标签页打开,长生命周期令牌不被暴露,防止点击劫持。
问题
Enable customers to launch an OpenClaw AI agent from a single button in their panel, with the UI automatically signed in and accessed securely through a per-user reverse proxy.
结果
Customers can launch and use OpenClaw with a single button, the UI is served under a per‑user sub‑path, the long‑lived gateway token is never exposed, and clickjacking is mitigated by opening the UI in a new tab.
工作流
- Configure OpenClaw to serve its UI under a sub‑path and trust the local proxy: set gateway.controlUi.basePath, gateway.publicOrigin, and gateway.trustedProxies.
- Set up the front proxy (e.g., nginx) to forward the sub‑path to the agent’s loopback port without stripping the path.
- Ensure the UI cannot be framed by checking X‑Frame‑Options and Content‑Security‑Policy headers; open a new browser tab instead of an iframe.
- Use openclaw dashboard --json --no-open to obtain a browserUrl containing a single‑use bootstrap token; rewrite the URL to replace the loopback origin with the public host and validate the fragment.
- Redirect the user’s browser to the rewritten URL, which authenticates automatically and opens the agent UI signed in.
证据
openclaw config set gateway.controlUi.basePath /user-alice/openclaw openclaw config set gateway.publicOrigin https://server.example.com openclaw config set gateway.trustedProxies '"127.0.0.1"'
curl -sI https://server.example.com/user-alice/openclaw/ | grep -i -E 'x-frame-options|content-security-policy' # x-frame-options: DENY # content-security-policy: ... frame-ancestors 'none' ...
- 记录日期: 2026-10-20T14:56:02.311Z