使用反向代理时,必须显式声明受信代理
如必须接入公网或对接企业微信、QQ机器人等,使用反向代理时必须明确声明受信代理,且确保反向代理必须传递真实客户端IP地址。
操作步骤
- 方式一:
- 配置OpenClaw网关的代理服务器IP地址。
openclaw config set gateway.trustedProxies[0] "127.0.0.1" openclaw config set gateway.trustedProxies[1] "::1"
- 设置认证模式为trusted-proxy。
openclaw config set gateway.auth.mode "trusted-proxy"
- 设置用户头字段。
openclaw config set gateway.auth.trustedProxy.userHeader "x-forwarded-user"
- 设置允许的用户列表,以user@example.com为例,请根据实际用户修改。
openclaw config set gateway.auth.trustedProxy.allowUsers[0] "user@example.com"
- 重启OpenClaw网关。
openclaw gateway restart
- 配置OpenClaw网关的代理服务器IP地址。
- 方式二
- 打开配置文件。
vim ~/.openclaw/openclaw.json
- 按“i”进入编辑模式,请添加如下内容。
"gateway": { "auth": { "mode": "trusted-proxy", "trustedProxy": { "userHeader": "x-forwarded-user", "allowUsers": [ "user@example.com" ] } }, "trustedProxies": [ "127.0.0.1" ] } - 按“Esc”键退出编辑模式,输入:wq!,按“Enter”键保存并退出文件。
- 重启OpenClaw网关。
openclaw gateway restart
- 打开配置文件。
父主题: 网络配置