1714 字
9 分钟
Xray Reality 配置教程:让代理流量完美伪装 HTTPS

引言:为什么需要 Reality#

在网络审查日益严格的今天,普通的代理协议很容易被检测和封锁。传统的 TLS 加密虽然能隐藏内容,但无法隐藏流量特征。

Reality 协议的优势:

  • 完美伪装:流量特征与正常 HTTPS 网站完全一致
  • 零信任架构:即使私钥泄露,攻击者也无法伪造服务器
  • 性能优异:基于 X25519 密钥交换,加密开销极低
  • 抗检测能力强:有效规避深度包检测(DPI)

1. Reality 原理简介#

1.1 核心概念#

概念说明
X25519椭圆曲线密钥交换算法,生成临时密钥对
Short ID短标识符,用于快速区分不同的 Reality 服务
Server Name伪装的目标网站域名(SNI)
Destination目标网站地址,用于获取证书指纹
Show是否显示证书指纹(调试用)

1.2 工作流程#

1. 客户端连接到服务器
2. 客户端发送 TLS ClientHello
3. 服务器使用 X25519 生成临时密钥对
4. 客户端验证服务器证书指纹
5. 双方协商共享密钥
6. 建立加密隧道开始通信

1.3 与传统 TLS 的区别#

对比项传统 TLSReality
证书需要 CA 签发证书使用目标网站证书指纹
密钥交换RSA/ECDHX25519
伪装性可被识别为代理完全伪装成正常 HTTPS
安全性依赖证书机构零信任架构

2. 服务器端配置#

2.1 安装 Xray#

Terminal window
# 更新系统
sudo apt update && sudo apt upgrade -y
# 安装 Xray
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
# 验证安装
xray version

2.2 生成 Reality 密钥#

Terminal window
# 生成 X25519 密钥对
xray x25519
# 输出示例:
# Private key: YmFzZTY0LWtleS12YWxpZGF0aW9uLWtleQ==
# Public key: cHJpbnQta2V5LmNvbmZpZy54cmF5Lm5ldC8=
# 保存密钥(稍后配置需要)
PRIVATE_KEY="YmFzZTY0LWtleS12YWxpZGF0aW9uLWtleQ=="
PUBLIC_KEY="cHJpbnQta2V5LmNvbmZpZy54cmF5Lm5ldC8="

2.3 获取目标网站证书指纹#

Terminal window
# 获取目标网站的证书指纹
# 推荐使用知名网站,如 www.bing.com
# 方法一:使用 openssl
openssl s_client -connect www.bing.com:443 < /dev/null 2>/dev/null \
| openssl x509 -fingerprint -noout | sed 's/.*=//'
# 方法二:使用 xray 自带工具
xray tls certChainHash --domain www.bing.com
# 输出示例:
# SHA256 Fingerprint=ABC123DEF456...

2.4 创建配置文件#

创建 /etc/xray/config.json

{
"log": {
"loglevel": "warning"
},
"inbounds": [
{
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "your-uuid-here",
"flow": "xtls-rprx-vision"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {
"show": false,
"dest": "www.bing.com:443",
"xver": 0,
"serverNames": ["www.bing.com"],
"privateKey": "your-private-key-here",
"shortIds": [""]
}
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
]
}

2.5 配置说明#

{
"realitySettings": {
"show": false, // 是否显示调试信息(生产环境设为false)
"dest": "www.bing.com:443", // 目标网站地址和端口
"xver": 0, // 伪造 HTTP 版本(0/1/2)
"serverNames": ["www.bing.com"], // 允许的 SNI 列表
"privateKey": "...", // 服务器私钥(xray x25519 生成)
"shortIds": [""] // Short ID 列表(空字符串表示匹配所有)
}
}

2.6 启动服务#

Terminal window
# 启动 Xray
sudo systemctl start xray
# 设置开机自启
sudo systemctl enable xray
# 检查状态
sudo systemctl status xray
# 查看日志
sudo journalctl -u xray -f

3. 客户端配置#

3.1 Clash Meta 配置#

proxies:
- name: "Reality-Server"
type: vless
server: your-server-ip
port: 443
uuid: your-uuid-here
flow: "xtls-rprx-vision"
cipher: auto
tls: true
reality-opts:
public-key: your-public-key-here
short-id: ""
server-name: "www.bing.com"
skip-cert-verify: false
proxy-groups:
- name: "自动选择"
type: select
proxies:
- Reality-Server
- 直接
rules:
- MATCH,自动选择

3.2 Shadowrocket 配置#

协议:VLESS
地址:your-server-ip
端口:443
UUID:your-uuid-here
加密方式:none
传输方式:tcp
TLS:开启
SNI:www.bing.com
Reality:开启
PublicKey:your-public-key-here
ShortId:(空)
Flow:xtls-rprx-vision

3.3 手动配置链接#

vless://your-uuid-here@your-server-ip:443?security=reality&encryption=none&flow=xtls-rprx-vision&sni=www.bing.com&fp=chrome&pbk=your-public-key-here&sid=&type=tcp#Reality-Server

4. 高级配置#

4.1 多目标网站配置#

{
"realitySettings": {
"show": false,
"dest": "www.bing.com:443",
"xver": 0,
"serverNames": [
"www.bing.com",
"www.google.com",
"www.apple.com",
"www.microsoft.com"
],
"privateKey": "your-private-key-here",
"shortIds": [""]
}
}

4.2 自定义 Short ID#

Terminal window
# 生成随机 Short ID
openssl rand -hex 8
# 配置多个 Short ID
{
"shortIds": [
"abc123def4567890",
"fedcba0987654321",
""
]
}

4.3 配合 WebSocket 使用#

{
"streamSettings": {
"network": "ws",
"security": "reality",
"realitySettings": {
"show": false,
"dest": "www.bing.com:443",
"xver": 0,
"serverNames": ["www.bing.com"],
"privateKey": "your-private-key-here",
"shortIds": [""]
},
"wsSettings": {
"path": "/",
"headers": {
"Host": "www.bing.com"
}
}
}
}

4.4 配合 gRPC 使用#

{
"streamSettings": {
"network": "grpc",
"security": "reality",
"realitySettings": {
"show": false,
"dest": "www.bing.com:443",
"xver": 0,
"serverNames": ["www.bing.com"],
"privateKey": "your-private-key-here",
"shortIds": [""]
},
"grpcSettings": {
"serviceName": "www.bing.com"
}
}
}

5. 性能优化#

5.1 开启 BBR 加速#

Terminal window
# 检查是否支持 BBR
lsmod | grep bbr
# 开启 BBR
echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
# 验证
sysctl net.ipv4.tcp_congestion_control

5.2 优化内核参数#

Terminal window
cat > /etc/sysctl.d/xray.conf << EOF
net.ipv4.tcp_fastopen=3
net.ipv4.tcp_tw_reuse=1
net.ipv4.ip_local_port_range=1024 65535
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.ipv4.tcp_max_syn_backlog=16384
net.ipv4.tcp_max_tw_buckets=10000
EOF
sudo sysctl -p /etc/sysctl.d/xray.conf

5.3 优化 Xray 配置#

{
"inbounds": [
{
"port": 443,
"protocol": "vless",
"settings": {
"clients": [...],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {...},
"tcpSettings": {
"header": {
"type": "none"
}
}
}
}
]
}

6. 安全加固#

6.1 防火墙配置#

Terminal window
# 安装 ufw
sudo apt install -y ufw
# 允许必要端口
sudo ufw allow 443/tcp
sudo ufw allow 22/tcp
# 启用防火墙
sudo ufw enable
# 查看状态
sudo ufw status

6.2 禁用密码登录#

Terminal window
# 编辑 SSH 配置
sudo nano /etc/ssh/sshd_config
# 修改:
# PasswordAuthentication no
# ChallengeResponseAuthentication no
# PubkeyAuthentication yes
# 重启 SSH
sudo systemctl restart sshd

6.3 定期更新密钥#

Terminal window
# 定期重新生成密钥对
xray x25519
# 更新服务器配置
# 更新所有客户端配置
# 建议每 3-6 个月更新一次

7. 常见问题排查#

7.1 无法连接#

问题排查方法
端口不通nc -zv your-server-ip 443
防火墙拦截sudo ufw status
服务未启动sudo systemctl status xray
密钥不匹配检查 Public Key 是否正确

7.2 连接不稳定#

问题解决方法
网络波动尝试更换目标网站
证书过期更新目标网站证书指纹
服务器负载高升级 VPS 配置

7.3 被封锁#

问题解决方法
IP 被封更换 VPS IP
协议被检测更换传输方式(ws/gRPC)
SNI 被封锁更换目标网站

7.4 调试技巧#

Terminal window
# 开启调试模式
# 修改配置文件 "show": true
# 查看详细日志
sudo journalctl -u xray -f
# 使用 xray 自带工具测试
xray diag
# 检查证书指纹
xray tls certChainHash --domain www.bing.com

8. 最佳实践建议#

8.1 目标网站选择#

Terminal window
# 推荐目标网站:
# 1. 知名大网站(稳定,不易被封锁)
# 2. 使用 HTTPS 的网站
# 3. 证书有效期长的网站
# 4. 支持 TLS 1.3 的网站
# 推荐列表:
# - www.bing.com
# - www.google.com
# - www.apple.com
# - www.microsoft.com
# - www.github.com

8.2 定期维护#

Terminal window
# 定期检查:
# 1. 服务器状态(每周)
# 2. 证书指纹(每月)
# 3. 密钥更新(每季度)
# 4. 日志检查(每天)
# 自动化脚本示例:
#!/bin/bash
# 检查 Xray 服务状态
if ! systemctl is-active --quiet xray; then
systemctl restart xray
echo "Xray 服务已重启" | mail -s "Xray 服务异常" [email protected]
fi

8.3 多服务器备份#

Terminal window
# 建议部署至少 2 台服务器
# 主服务器 + 备用服务器
# 避免单点故障
# Clash 配置示例:
proxy-groups:
- name: "自动选择"
type: url-test
url: "http://www.gstatic.com/generate_204"
interval: 300
proxies:
- Reality-Server-1
- Reality-Server-2
- 直接

结语#

Xray Reality 是目前最先进的代理协议之一,通过完美伪装 HTTPS 流量,可以有效规避网络审查。虽然配置过程相对复杂,但一旦完成,就能获得极高的安全性和稳定性。

TIP

如果不想自己搭建,可以选择支持 Reality 协议的机场,省心省力。


想了解更多代理配置技巧?请订阅我们的 Telegram 频道 或持续关注本站。

Xray Reality 配置教程:让代理流量完美伪装 HTTPS
https://888479.xyz/posts/xray-reality-configuration-guide-perfect-https-camouflage/
作者
888479
发布于
2026-07-12
许可协议
CC BY-NC-SA 4.0