VPS + Xray Reality 翻墙部署指南
本文记录基于搬瓦工 VPS 部署 Xray + Reality 代理的完整流程,以及各平台客户端配置方法。仅供个人维护参考。
一、方案概述
| 方案 | 难度 | 抗封锁 | 说明 |
|---|---|---|---|
| Xray + Reality | 中 | 高 | 首选,流量伪装成正常 HTTPS |
| Trojan + TLS | 中 | 较高 | 需域名和证书 |
| WireGuard | 低 | 一般 | 简单但易被识别 |
| Shadowsocks 一键 | 很低 | 较低 | 搬瓦工面板自带,适合临时使用 |
本站点采用 Reality「偷自己」 方案:Xray 监听 443 端口,nginx 网站迁移至 127.0.0.1:8443,外部探测看到的是正常网站,不影响 littlepudding8.com 运行。
客户端 ──加密──▶ VPS:443 (Xray Reality) ──▶ 目标网站
│
└─ fallback ──▶ 127.0.0.1:8443 (nginx 网站)
二、服务器环境
| 项目 | 值 |
|---|---|
| 服务商 | 搬瓦工 (BandwagonHost) |
| 系统 | Ubuntu 22.04 LTS |
| IP | 144.34.187.175 |
| SSH 密钥 | ~/.ssh/bw_key01~ |
| 网站 | littlepudding8.com(WordPress + nginx) |
三、服务器端部署
3.1 安装依赖与 Xray
# SSH 登录
ssh -i ~/.ssh/bw_key01~ [email protected]
# 安装依赖
apt update && apt install -y unzip curl ca-certificates
# 安装 Xray(官方脚本)
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
# 验证
xray version
3.2 迁移 nginx(保留网站)
# 将 nginx 从 443 改到本地 8443
sed -i 's/listen 443 ssl;/listen 127.0.0.1:8443 ssl;/' \
/etc/nginx/sites-enabled/littlepudding8.com
nginx -t && systemctl reload nginx
3.3 生成密钥
UUID=$(xray uuid)
KEYS=$(xray x25519)
PRIVATE_KEY=$(echo "$KEYS" | grep PrivateKey | awk -F': ' '{print $2}')
PUBLIC_KEY=$(echo "$KEYS" | grep PublicKey | awk -F': ' '{print $2}')
SHORT_ID=$(openssl rand -hex 4)
echo "UUID=$UUID"
echo "PRIVATE_KEY=$PRIVATE_KEY"
echo "PUBLIC_KEY=$PUBLIC_KEY"
echo "SHORT_ID=$SHORT_ID"
注意: 新版 Xray 的
xray x25519输出格式为PrivateKey:和Password (PublicKey):,解析时用awk -F': ',不要用旧版grep Private | awk '{print $3}'。
3.4 写入配置
配置文件路径:/usr/local/etc/xray/config.json
{
"log": { "loglevel": "warning" },
"inbounds": [{
"listen": "0.0.0.0",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [{
"id": "
<UUID>",
"flow": "xtls-rprx-vision"
}],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {
"show": false,
"dest": "127.0.0.1:8443",
"xver": 0,
"serverNames": ["littlepudding8.com", "www.littlepudding8.com"],
"privateKey": "
<PRIVATE_KEY>",
"shortIds": ["
<SHORT_ID>"]
}
},
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls", "quic"]
}
}],
"outbounds": [
{ "protocol": "freedom", "tag": "direct" },
{ "protocol": "blackhole", "tag": "block" }
]
}
3.5 启动与验证
xray run -test -config /usr/local/etc/xray/config.json
systemctl restart xray && systemctl enable xray
systemctl status xray
# 确认端口
ss -tlnp | grep -E ':443|:8443'
# 期望:xray 占 443,nginx 占 127.0.0.1:8443
四、当前节点信息
| 参数 | 值 |
|---|---|
| 地址 | 144.34.187.175 |
| 端口 | 443 |
| UUID | 80eae368-1092-4994-b3e1-381af94d7d05 |
| Flow | xtls-rprx-vision |
| 传输 | TCP |
| 安全 | Reality |
| SNI | littlepudding8.com |
| Public Key | BeJ-CTA_bRTTPIULzRQrvyZZrJ9bEBPM5dbYPAExY |
| Short ID | 22600e3c |
| Fingerprint | chrome |
| 加密 | none |
v2rayN 导入链接:
vless://[email protected]:443?encryption=none&flow=xtls-rprx-vision&security=reality&sni=littlepudding8.com&fp=chrome&pbk=B_eJ_-CTA_bRTTPIULzRQrvyZZrJ9bEBPM5dbYPAExY&sid=22600e3c&type=tcp#Bandwagon-Reality
服务器备份路径:/root/xray-client-info.txt
五、客户端配置
5.1 推荐客户端
| 平台 | 软件 | 说明 |
|---|---|---|
| Windows | v2rayN | 支持 Xray 核心,推荐 |
| macOS | v2rayN | 下载 macos-arm64 或 macos-64 版 |
| Ubuntu 桌面 | v2rayN | 用 .deb 安装,核心选 Xray |
| iPhone | Shadowrocket / Stash | App Store 购买 |
| Android | v2rayNG | 支持 VLESS Reality |
注意: Nekoray 4.x 已移除 Xray 核心支持,Reality 节点请用 v2rayN 或 v2rayNG。
5.2 Ubuntu 桌面安装 v2rayN
sudo apt update
sudo apt install -y curl libgtk-3-0 libnotify4 libnss3 libxss1
cd ~/Downloads
curl -L -C - --retry 10 --retry-delay 3 \
-o v2rayN-linux-64.deb \
https://github.com/2dust/v2rayN/releases/latest/download/v2rayN-linux-64.deb
sudo apt install -y ./v2rayN-linux-64.deb
若 zip 下载中断报错 Transferred a partial file,用 curl -L -C - 断点续传,或改用 .deb 包。
5.3 导入与连接
- 复制上方
vless://链接 - v2rayN → 服务器 → 从剪贴板导入服务器
- 设置 → Core 类型 → 选择 Xray
- 设为活动服务器 → 开启系统代理或 TUN 模式
- 测试:
curl -I https://www.google.com
5.4 macOS 安装 v2rayN
cd ~/Downloads
# Apple Silicon (M 系列)
curl -L -C - --retry 10 -o v2rayN-macos-arm64.zip \
https://github.com/2dust/v2rayN/releases/latest/download/v2rayN-macos-arm64.zip
unzip v2rayN-macos-arm64.zip -d ~/v2rayN
cd ~/v2rayN && chmod +x v2rayN && ./v2rayN
# 若提示"已损坏"
xattr -cr ~/v2rayN
六、运维命令
systemctl status xray # 查看状态
systemctl restart xray # 重启
journalctl -u xray -f # 查看日志
cat /root/xray-client-info.txt # 查看客户端配置
xray run -test -config /usr/local/etc/xray/config.json # 测试配置
ss -tlnp | grep -E ':443|:8443' # 查看端口
七、常见问题
| 现象 | 原因与处理 |
|---|---|
| 客户端连不上 | 确认 Flow=xtls-rprx-vision、SNI=littlepudding8.com、核心选 Xray |
| zip 解压失败 | 下载不完整,用 curl -L -C - 断点续传,或改用 .deb |
| 443 被 nginx 占用 | 检查 nginx 是否已改到 127.0.0.1:8443 |
xray 配置为空 {} |
重新执行密钥生成和 config.json 写入 |
| Private Key 解析为空 | 新版 xray 输出格式变了,用 awk -F': ' 解析 |
| 网站打不开 | 检查 nginx:curl -sk https://127.0.0.1:8443/ -H "Host: littlepudding8.com" |
八、安全建议
- SSH 使用密钥登录,关闭密码登录
- 防火墙只开放 22、443 端口
- 定期
apt update && apt upgrade - 节点信息含敏感凭据,文章设为私有,勿公开分享
- 若密钥泄露,重新生成 UUID 和 Reality 密钥对并更新 config.json
最后更新:2026-06-29