---
title: 使用反向代理时，必须显式声明受信代理
description: "如必须接入公网，使用反向代理时必须明确声明受信代理，且确保反向代理必须传递真实客户端IP地址。关闭公网访问或接企业微信、QQ机器人等无需配置此项。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengcctrustzone/tee/cVMcont/kunpengtee_zjsj_openclaw_047.html
sourcePath: /source/zh/kunpengcctrustzone/tee/cVMcont/kunpengtee_zjsj_openclaw_047.html
indexId: 083aedb0c840bb6e5e93d149ddc3b0ea466e1e90d959dead111504cd7a6f785675
---
# 使用反向代理时，必须显式声明受信代理

如必须接入公网，使用反向代理时必须明确声明受信代理，且确保反向代理必须传递真实客户端IP地址。关闭公网访问或接企业微信、QQ机器人等无需配置此项。

#### 操作步骤

- 方式一：

  1. 配置OpenClaw网关的代理服务器IP地址。

```
openclaw config set gateway.trustedProxies[0] "127.0.0.1"
openclaw config set gateway.trustedProxies[1] "::1"
```


  2. 设置认证模式为trusted-proxy。

```
openclaw config set gateway.auth.mode "trusted-proxy"
```


  3. 设置用户头字段。

```
openclaw config set gateway.auth.trustedProxy.userHeader "x-forwarded-user"
```


  4. 设置允许的用户列表，以user@example.com为例，请根据实际用户修改。

```
openclaw config set gateway.auth.trustedProxy.allowUsers[0] "user@example.com"
```


  5. 重启OpenClaw网关。

```
openclaw gateway restart
```


- 方式二

  1. 打开配置文件。

```
vim
~
/.openclaw/openclaw.json
```


  2. 按“i”进入编辑模式，请添加如下内容。

```
"gateway": {
"auth": {
"mode": "trusted-proxy",
"trustedProxy": {
"userHeader": "x-forwarded-user",
"allowUsers": [
"user@example.com"
]
}
},
"trustedProxies": [
"127.0.0.1"
]
}
```


  3. 按“Esc”键退出编辑模式，输入:wq!，按“Enter”键保存并退出文件。
  4. 重启OpenClaw网关。

```
openclaw gateway restart
```
