被限制访问 VPS 的现代网络架构实践:VLESS + XHTTP + TLS + WARP 出站配置指南
本文记录一套现代化 Xray 网络架构部署流程,包括 Cloudflare CDN、VLESS XHTTP、TLS、后量子密钥交换以及 Cloudflare WARP 出站优化。
适用于希望提升网络稳定性、安全性以及可维护性的服务器环境。
—
一、整体架构
传统单节点架构:
客户端
|
|
VPS IP
|
|
Xray
|
|
目标网站
存在的问题:
- VPS IP 暴露
- IP 可能受到网络限制
- 出口质量受服务器线路影响
- TLS 证书需要自行维护
—
本文采用以下架构:
Cloudflare CDN
|
|
客户端
|
|
VLESS + XHTTP + TLS
|
|
Cloudflare
|
|
VPS Xray 服务端
|
|
路由分流
|
+----------------+
| |
direct WARP
|
|
Cloudflare Network
最终实现:
- Cloudflare 隐藏源站 IP
- VLESS 用户认证
- XHTTP 现代传输协议
- TLS 加密通信
- 后量子密钥交换支持
- WARP 优化指定出口
—
二、准备环境
1. VPS
推荐系统:
- Debian 12
- Ubuntu 22.04+
- Ubuntu 24.04
更新系统:
apt update && apt upgrade -y
安装常用工具:
apt install curl wget unzip nano -y
—
2. 域名
准备一个域名:
例如:
node.example.com
将域名接入 Cloudflare。
DNS 添加:
最终结构:
node.example.com
↓
Cloudflare
↓
VPS
—
三、安装 Xray
使用官方安装脚本:
bash <(curl -Ls https://github.com/XTLS/Xray-install/raw/main/install-release.sh)
检查版本:
xray version
正常输出:
Xray x.xx.x
配置文件位置:
/usr/local/etc/xray/config.json
—
四、使用 Cloudflare Origin Certificate 配置 TLS
如果域名已经接入 Cloudflare,可以使用:
Cloudflare Origin Certificate(源服务器证书)
替代 Let’s Encrypt。
优势
相比 ACME:
- 不需要开放 80 端口
- 不需要自动续期
- 有效期更长
- Cloudflare 到源站保持 TLS 加密
架构:
用户
HTTPS
Cloudflare
Origin TLS
VPS
—
1. 创建 Cloudflare 源服务器证书
进入:
Cloudflare Dashboard
↓
SSL/TLS
↓
Origin Server
↓
Create Certificate
选择:
Generate private key and CSR with Cloudflare
填写域名:
例如:
node.example.com
或者:
*.example.com
有效期:
15 years
生成:
Origin Certificate
Private Key
—
2. 上传证书到 VPS
创建目录:
mkdir -p /etc/xray/cert
保存:
/etc/xray/cert/origin.pem
/etc/xray/cert/origin.key
修改权限:
chmod 600 /etc/xray/cert/*
—
3. Cloudflare SSL 设置
进入:
SSL/TLS
设置:
Full (strict)
不要使用:
Flexible
原因:
Flexible 模式:
Cloudflare
↓
HTTP
↓
VPS
源站之间没有 TLS 加密。
—
五、配置 VLESS + XHTTP + TLS
生成 UUID:
xray uuid
示例:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
编辑:
nano /usr/local/etc/xray/config.json
配置:
{
"inbounds": [
{
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "你的UUID",
"email": "user@example.com",
"encryption": "none"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "xhttp",
"security": "tls",
"tlsSettings": {
"certificates": [
{
"certificateFile":
"/etc/xray/cert/origin.pem",
"keyFile":
"/etc/xray/cert/origin.key"
}
]
},
"xhttpSettings": {
"path":
"/随机路径"
}
}
}
]
}
—
六、启动 Xray
检查配置:
xray run -test \
-config /usr/local/etc/xray/config.json
无错误后:
启动:
systemctl restart xray
查看状态:
systemctl status xray
查看日志:
journalctl -u xray -f
—
七、客户端配置
客户端参数:
| 项目 | 内容 |
| 协议 | VLESS |
| 地址 | node.example.com |
| 端口 | 443 |
| 传输 | XHTTP |
| 安全 | TLS |
| UUID | 你的UUID |
| 路径 | 你的Path |
推荐客户端:
- Windows:v2rayN
- Android:v2rayNG
- iOS:Shadowrocket
—
八、启用后量子密钥交换
新版 Xray 支持:
X25519MLKEM768
其中:
ML-KEM-768
属于后量子密钥封装算法。
作用:
注意:
后量子算法不会替代 TLS,而是在密钥交换阶段提供额外保护。
需要:
—
九、为什么加入 WARP 出站?
默认:
用户
↓
VPS
↓
互联网
出口完全依赖 VPS 网络。
加入 WARP:
用户
↓
Xray
↓
Cloudflare WARP
↓
互联网
优势:
- 增加出口选择
- 优化部分访问路径
- 隔离 VPS 原始出口
十、使用 wgcf 获取 Cloudflare WARP 参数
Xray 的 WireGuard 出站需要以下参数:
| 参数 | 说明 |
| PrivateKey | WARP 私钥 |
| Address | WARP 虚拟地址 |
| PublicKey | Cloudflare WARP 公钥 |
| Endpoint | WARP 节点地址 |
| Reserved | WireGuard 保留字段 |
推荐使用 wgcf 获取完整配置。
项目地址:
https://github.com/ViRb3/wgcf
—
1. 下载 wgcf
创建目录:
mkdir ~/wgcf
cd ~/wgcf
下载:
wget https://github.com/ViRb3/wgcf/releases/latest/download/wgcf_2.2.22_linux_amd64
重命名:
mv wgcf_2.2.22_linux_amd64 wgcf
添加执行权限:
chmod +x wgcf
—
2. 注册 WARP
执行:
./wgcf register
成功后生成:
wgcf-account.toml
该文件保存 WARP 账户信息。
—
3. 生成 WireGuard 配置
执行:
./wgcf generate
生成:
wgcf-profile.conf
查看:
cat wgcf-profile.conf
示例:
[Interface]
PrivateKey = YOUR_PRIVATE_KEY
Address = 172.16.0.2/32
Address = 2606:4700:xxxx::xxxx/128
DNS = 1.1.1.1
MTU = 1280
[Peer]
PublicKey = WARP_PUBLIC_KEY
AllowedIPs = 0.0.0.0/0
AllowedIPs = ::/0
Endpoint = engage.cloudflareclient.com:2408
—
十一、配置 Xray WireGuard 出站
Xray 支持原生 WireGuard outbound。
最终结构:
VLESS + XHTTP
|
|
Xray
|
|
WireGuard outbound
|
|
Cloudflare WARP
|
|
Internet
—
参数转换
wgcf-profile.conf:
| wgcf | Xray |
| PrivateKey | secretKey |
| Address | address |
| PublicKey | peers.publicKey |
| Endpoint | peers.endpoint |
| AllowedIPs | allowedIPs |
—
添加 WARP outbound
编辑:
nano /usr/local/etc/xray/config.json
添加:
{
"tag": "warp",
"protocol": "wireguard",
"settings": {
"secretKey":
"你的WARP_PRIVATE_KEY",
"address": [
"172.16.0.2/32",
"2606:4700:xxxx::xxxx/128"
],
"peers": [
{
"publicKey":
"WARP_PUBLIC_KEY",
"endpoint":
"engage.cloudflareclient.com:2408",
"allowedIPs": [
"0.0.0.0/0",
"::/0"
]
}
],
"reserved": [
0,
0,
0
],
"mtu": 1280
}
}
—
关于 reserved 参数
Cloudflare WARP WireGuard 配置包含:
Reserved
字段。
它对应 WireGuard 数据包中的三个保留字节。
如果:
wgcf-profile.conf
中没有显示:
Reserved
则:
"reserved":[0,0,0]
即可。
如果使用其他 WARP 配置生成工具,并提供:
例如:
Reserved = 1,2,3
则填写:
"reserved":[1,2,3]
—
十二、配置路由分流
Xray 通过 routing 控制哪些流量走 WARP。
—
示例 1:指定域名走 WARP
例如:
{
"type": "field",
"domain": [
"geosite:google",
"geosite:openai"
],
"outboundTag": "warp"
}
效果:
Google
↓
WARP
—
示例 2:指定 IP 走 WARP
例如:
{
"type":"field",
"ip":[
"geoip:us"
],
"outboundTag":"warp"
}
—
示例 3:全部流量走 WARP
测试阶段可以:
{
"type":"field",
"network":"tcp,udp",
"outboundTag":"warp"
}
确认正常后,再调整分流规则。
—
十三、重启并测试
检查 Xray:
xray run -test \
-config /usr/local/etc/xray/config.json
重启:
systemctl restart xray
查看日志:
journalctl -u xray -f
—
测试 WARP 状态
执行:
curl https://www.cloudflare.com/cdn-cgi/trace
查看:
warp=on
表示 WARP 正常工作。
—
检查 IPv4 / IPv6 出口
测试:
curl -4 ip.sb
以及:
curl -6 ip.sb
如果两个出口不一致:
可能导致:
建议保持:
IPv4
↓
WARP
IPv6
↓
WARP
或者关闭不需要的 IPv6。
—
十四、常见问题
1. Cloudflare 开启代理后无法连接
检查:
Cloudflare SSL:
必须:
Full (strict)
—
VPS 防火墙:
开放:
443/tcp
例如:
ufw allow 443/tcp
—
Xray 状态:
检查:
systemctl status xray
—
2. Google 出现异常流量提示
可能原因:
WARP 共享出口
Cloudflare WARP 使用共享 IP:
多个用户可能使用相同出口。
—
IPv4 / IPv6 不一致
检查:
curl -4 ip.sb
curl -6 ip.sb
如果:
IPv4 ≠ IPv6
可能触发部分网站风控。
—
3. XHTTP 无法连接
检查:
- path 是否一致
- Cloudflare 是否开启代理
- TLS 模式是否正确
- 客户端版本是否支持 XHTTP
—
十五、不想自行维护服务器?
自行搭建需要:
- VPS 管理经验
- Linux 运维
- Xray 配置
- 节点维护
如果:
- 没有自己的服务器
- 不想维护系统
- 希望直接使用成熟配置
可以选择 NBNet:
注册链接:
https://nbnet.vip/#/register?code=iLWX0mGp
NBNet 提供:
- 多地区节点接入
- VLESS 协议支持
- XHTTP / Reality 等现代协议
- 多设备支持
- 在线订阅管理
适合希望直接使用,而不是自行维护服务器环境的用户。
—
总结
本文搭建的架构:
Cloudflare CDN
+
VLESS
+
XHTTP
+
TLS
+
X25519MLKEM768
+
WARP WireGuard outbound
相比传统单 VPS 架构:
- 隐藏源站入口
- 提升维护便利性
- 提供更灵活的出口控制
- 支持现代传输协议
- 增强密钥交换安全性
通过 Cloudflare、Xray 与 WARP 的组合,可以构建一套更加现代化、可维护的网络架构。