Cloudflare WARP Zero Trust 代理模式 + sing-box VLESS-REALITY 完整配置记录
流量链路如下:
Windows Clash (TUN/mixed)
→ VPS sing-box :443 (VLESS-REALITY)
├─ anthropic.com / claude.ai / openai.com / chatgpt.com
│ → WARP Proxy 127.0.0.1:40000 → Cloudflare Zero Trust → 目标
└─ 其他流量
→ direct → 目标
删除旧注册,发起新注册(替换为你的 Zero Trust 组织名)
# 删除旧注册
warp-cli registration delete
# 发起新注册
warp-cli --accept-tos registration new YOUR_ORG_NAME
命令执行后浏览器会打开认证页面,认证成功后浏览器会尝试跳转到:
com.cloudflare.warp://YOUR_ORG.cloudflareaccess.com/auth?token=XXXXXX
复制 token= 后面的完整字符串
在服务器上手动传入 token(因为浏览器在 Windows,token 不会自动传回服务器)
warp-cli registration token XXXXXX
设置代理模式并连接
warp-cli mode proxy
warp-cli proxy port 40000
warp-cli connect
warp-cli status
路径:Zero Trust 后台 → Team & Resources → Devices → Device profiles → Default
| 设置项 | 值 | 说明 |
|---|---|---|
| Service mode | Local proxy mode | 必须设为此模式,否则无法切换为 proxy |
| Allow Mode Switch | true | 允许客户端切换模式 |
Mode: WarpProxy on port 40000 # 代理模式,不接管全局流量
Always On: true # 断线自动重连
Auto Connect: 3 # 开机自动连接
Organization: Your Team Name # Zero Trust 组织
Protocol: MASQUE (HTTP/3) # 连接协议
配置文件路径:/etc/sing-box/config.json
{
"log": { "level": "info" },
"inbounds": [
{
"type": "vless",
"tag": "vless-reality-in",
"listen": "::",
"listen_port": 443,
"users": [{ "uuid": "YOUR_UUID", "flow": "" }],
"tls": {
"enabled": true,
"server_name": "www.microsoft.com",
"reality": {
"enabled": true,
"handshake": { "server": "www.microsoft.com", "server_port": 443 },
"private_key": "YOUR_PRIVATE_KEY",
"short_id": ["YOUR_SHORT_ID"]
}
}
}
],
"outbounds": [
{
// OpenAI / Claude 走 WARP 代理
"type": "socks",
"tag": "warp-out",
"server": "127.0.0.1",
"server_port": 40000,
"version": "5"
},
{ "type": "direct", "tag": "direct" },
{ "type": "block", "tag": "block" }
],
"route": {
"rules": [
{
"domain_suffix": [
"anthropic.com",
"claude.ai",
"openai.com",
"chatgpt.com",
"oaiusercontent.com"
],
"outbound": "warp-out"
}
],
"final": "direct"
}
}
# 重启服务
systemctl restart sing-box
# 查看状态
systemctl status sing-box
# 查看实时日志
journalctl -u sing-box -f
# 验证配置文件语法
sing-box check -c /etc/sing-box/config.json
# 查看连接状态
warp-cli status
# 确认走了 WARP
curl --socks5-hostname 127.0.0.1:40000 \
https://cloudflare.com/cdn-cgi/trace \
| grep -E "warp|ip"
# 期望输出:
# ip=104.x.x.x (WARP IP)
# warp=on
# 测试 Claude(期望 302)
curl --socks5-hostname 127.0.0.1:40000 \
-I https://claude.ai
# 测试 OpenAI(期望 308)
curl --socks5-hostname 127.0.0.1:40000 \
-I https://chat.openai.com
# 测试服务器直连 Google
curl -I https://www.google.com
CloudflareWARP。gvisor 模式有独立用户态网络栈,无法识别该接口导致冲突。mixed / system 模式使用系统原生网络栈,可正确处理 WARP 虚拟接口。
| TUN Stack 模式 | 安装 WARP 后可用 | 说明 |
|---|---|---|
gvisor | ❌ 冲突 | 用户态网络栈,与 WARP 虚拟接口冲突 |
mixed | ✅ 正常 | 推荐使用 |
system | ✅ 正常 | 可用 |
Clash Verge → 设置 → TUN 模式 → Stack → 改为 mixed
| 问题 | 原因 | 解决方案 |
|---|---|---|
| Registration Missing due to Manual deletion | 注册被删除 | 重新执行注册流程,手动传入 token |
| warp-cli mode proxy 报 Invalid setting | Zero Trust 策略限制 | 后台 Device profile → Service mode 改为 Local proxy mode |
| WARP 接管全局流量导致 Clash 断连 | WARP 处于 Tunnel 模式 | 切换为 proxy 模式:warp-cli mode proxy |
| Clash TUN 模式无法访问网络 | gvisor 与 WARP 虚拟接口冲突 | TUN Stack 改为 mixed |
| claude.ai 返回 403 | 服务器 IP 被封,未走 WARP | 确认 sing-box 规则和 WARP 连接状态 |
# 断开重连以刷新 Zero Trust 策略
warp-cli disconnect
sleep 5
warp-cli connect
sleep 5
warp-cli mode proxy
warp-cli proxy port 40000
warp-cli status
# WARP 状态
warp-cli status
# sing-box 状态
systemctl status sing-box
# WARP 服务状态
systemctl status warp-svc
# Zero Trust 免费版限制
# - 最多 50 个设备
# - 无流量限制
# 开机自启已配置
# - warp-svc: 自动启动
# - sing-box: systemctl enabled