2065 字
10 分钟
V2Ray / VMess 完全配置指南 2026:服务端部署 + 客户端配置 + TLS + CDN 隐匿全攻略
V2Ray(及其增强版 Xray-core)是当前最主流的自建代理协议之一,支持 VMess、VLESS、Trojan 等多种协议,配合 TLS + WebSocket + CDN 可以实现极强的流量伪装。
本文从零开始,带你完成一个完整的 V2Ray 自建节点部署,覆盖两种主流方案:VMess + TLS + WS(适合配合 CDN) 和 VLESS + Reality(零流量特征,2026 最推荐)。
前置要求:一台境外 VPS(推荐 Vultr / BandwagonHost / DMIT),一个解析好的域名(可选,Reality 方案不需要域名)。
一、方案选择:VMess/TLS/WS vs VLESS/Reality
| 对比项 | VMess + TLS + WS(+ CDN) | VLESS + Reality |
|---|---|---|
| 隐匿性 | ⭐⭐⭐⭐(TLS 流量,CDN 后更强) | ⭐⭐⭐⭐⭐(模拟正常 HTTPS,几乎无特征) |
| 配置复杂度 | 中等(需要域名 + 证书 + Nginx) | 低(无需域名/证书,直接用 IP) |
| 连接速度 | 受 WebSocket 和 CDN 延迟影响 | 直连 VPS,延迟更低 |
| 抗封锁能力 | 高(IP 隐藏在 CDN 后面,封 CDN IP 代价大) | 极高(流量特征接近 0) |
| CDN 支持 | ✅(可以套 Cloudflare 隐藏 VPS IP) | ❌(直连,CDN 会破坏 Reality 指纹) |
| 适用场景 | VPS IP 被封时最后手段,CDN 续命 | 日常首选方案 |
2026 年推荐优先顺序:
1. VLESS + Reality(最推荐,新节点首选)2. VMess/VLESS + TLS + WS + Cloudflare CDN(VPS IP 被封时的保命方案)二、准备工作:VPS 初始化
# 登录 VPS(用 root 或 sudo 用户)ssh root@your.server.ip
# 更新系统(Debian/Ubuntu)apt update && apt upgrade -y
# 安装必要工具apt install -y curl wget vim git unzip
# 开启 BBR 拥塞控制算法(提升 TCP 吞吐量)echo "net.core.default_qdisc=fq" >> /etc/sysctl.confecho "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.confsysctl -p
# 验证 BBR 是否开启sysctl net.ipv4.tcp_congestion_control# 输出应为:net.ipv4.tcp_congestion_control = bbr
# 防火墙放行端口(ufw)ufw allow 22/tcp # SSHufw allow 80/tcp # HTTP(证书申请需要)ufw allow 443/tcp # HTTPS(TLS 方案)ufw allow 8443/tcp # 自定义端口(Reality 方案)ufw enable三、方案一:VLESS + Reality(推荐新节点使用)
Reality 是 Xray 独有的协议,通过”借用”真实网站的 TLS 指纹(如 Google、Apple),让你的代理流量看起来和普通 HTTPS 访问一模一样。
无需域名、无需证书,直接用 VPS IP 部署。
3.1 安装 Xray-core
# 官方安装脚本(推荐)bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
# 验证安装xray version# Xray 1.8.x by XTLS ...
# Xray 二进制路径:/usr/local/bin/xray# 配置文件路径:/usr/local/etc/xray/config.json# 服务管理:systemctl status xray3.2 生成 UUID 和 Reality 密钥对
# 生成 UUID(用户认证)xray uuid# 输出示例:f6b7d3e2-1a2b-3c4d-5e6f-7a8b9c0d1e2f
# 生成 Reality 密钥对(必须用 Xray 工具生成)xray x25519# 输出示例:# Private key: 0Hk...(服务端使用,保密!)# Public key: 3Km...(客户端使用,可公开)
# 生成 Short ID(可选,增加多路复用)openssl rand -hex 8# 示例:a1b2c3d4e5f6a7b83.3 服务端配置文件
# 编辑配置文件vim /usr/local/etc/xray/config.json{ "log": { "loglevel": "warning", "access": "/var/log/xray/access.log", "error": "/var/log/xray/error.log" },
"inbounds": [ { "listen": "0.0.0.0", "port": 8443, "protocol": "vless", "settings": { "clients": [ { "id": "f6b7d3e2-1a2b-3c4d-5e6f-7a8b9c0d1e2f", // 你的 UUID "flow": "xtls-rprx-vision" // Vision 流控(必须) } ], "decryption": "none" }, "streamSettings": { "network": "tcp", "security": "reality", "realitySettings": { "show": false, "dest": "www.apple.com:443", // 借用 Apple 的 TLS 指纹 "xver": 0, "serverNames": [ "www.apple.com" // 与 dest 对应 ], "privateKey": "0Hk...", // 服务端私钥(xray x25519 生成的 Private key) "shortIds": [ "a1b2c3d4e5f6a7b8" // Short ID(客户端也需要配置) ] } }, "sniffing": { "enabled": true, "destOverride": ["http", "tls"] } } ],
"outbounds": [ { "protocol": "freedom", "tag": "direct" }, { "protocol": "blackhole", "tag": "blocked" } ],
"routing": { "domainStrategy": "IPIfNonMatch", "rules": [ { "type": "field", "ip": ["geoip:private", "geoip:cn"], "outboundTag": "blocked" // 屏蔽对国内 IP 的访问请求 } ] }}# 启动并设置开机自启systemctl enable xraysystemctl restart xraysystemctl status xray
# 检查端口监听ss -tlnp | grep 84433.4 客户端连接信息(分享链接)
VLESS Reality 的分享链接格式:
vless://f6b7d3e2-1a2b-3c4d-5e6f-7a8b9c0d1e2f@your.server.ip:8443?encryption=none&flow=xtls-rprx-vision&security=reality&sni=www.apple.com&fp=chrome&pbk=3Km...&sid=a1b2c3d4e5f6a7b8&type=tcp&headerType=none#Reality-节点名
参数说明: uuid = 你的 UUID your.server.ip = VPS 公网 IP 8443 = 监听端口 sni = www.apple.com(与 serverNames 一致) fp = chrome(TLS 指纹,推荐 chrome/firefox/safari) pbk = Public key(xray x25519 生成的公钥) sid = Short ID四、方案二:VMess + TLS + WebSocket + Cloudflare CDN
适合 VPS IP 被封、需要用 CDN 隐藏 IP 的场景。
4.1 申请 TLS 证书(acme.sh)
# 安装 acme.shcurl https://get.acme.sh | sh -s email=your@email.comsource ~/.bashrc
# 申请 Let's Encrypt 证书(HTTP 验证方式,需要 80 端口可访问)# 先临时停止占用 80 端口的服务(如果有)systemctl stop nginx
~/.acme.sh/acme.sh --issue -d your.domain.com --standalone --server letsencrypt
# 安装证书到指定目录mkdir -p /etc/xray/ssl~/.acme.sh/acme.sh --install-cert -d your.domain.com \ --key-file /etc/xray/ssl/private.key \ --fullchain-file /etc/xray/ssl/fullchain.crt \ --reloadcmd "systemctl reload nginx"
# 验证证书ls -la /etc/xray/ssl/4.2 安装配置 Nginx
apt install -y nginx
# Nginx 配置文件cat > /etc/nginx/sites-available/v2ray << 'EOF'server { listen 80; server_name your.domain.com; # 强制 HTTP → HTTPS return 301 https://$server_name$request_uri;}
server { listen 443 ssl http2; server_name your.domain.com;
ssl_certificate /etc/xray/ssl/fullchain.crt; ssl_certificate_key /etc/xray/ssl/private.key; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m;
# 伪装:根路径返回正常网站(防止被探测) root /var/www/html; index index.html;
# V2Ray WebSocket 路径(要与 Xray 配置的 path 一致) location /ray { if ($http_upgrade != "websocket") { return 404; } proxy_pass http://127.0.0.1:10000; # 转发到本地 Xray 监听端口 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }}EOF
ln -s /etc/nginx/sites-available/v2ray /etc/nginx/sites-enabled/nginx -t # 验证配置systemctl reload nginx4.3 Xray 服务端配置(VMess + WS)
{ "log": { "loglevel": "warning" },
"inbounds": [ { "listen": "127.0.0.1", // 只监听本地(通过 Nginx 反代) "port": 10000, "protocol": "vmess", "settings": { "clients": [ { "id": "f6b7d3e2-1a2b-3c4d-5e6f-7a8b9c0d1e2f", // UUID "alterId": 0 // 0 = 启用 AEAD 加密(推荐) } ] }, "streamSettings": { "network": "ws", "wsSettings": { "path": "/ray" // 与 Nginx location 路径一致 } } } ],
"outbounds": [ { "protocol": "freedom", "tag": "direct" }, { "protocol": "blackhole", "tag": "blocked" } ]}4.4 配置 Cloudflare CDN(隐藏 VPS IP)
- 将域名 DNS 解析到 Cloudflare
- Cloudflare Dashboard → DNS → 将 A 记录设为橙色云(代理)
- SSL/TLS 设置 → 选择 Full(严格) 模式
- Cloudflare 支持 WebSocket:Speed → Optimization → 开启 WebSockets
- 客户端配置地址改为你的 域名,端口可用 Cloudflare 支持的端口:
- HTTP:80、8080、8880、2052、2082、2086、2095
- HTTPS:443、2053、2083、2087、2096、8443
五、客户端配置
5.1 Clash Verge Rev(Windows/macOS)
在「覆写」功能中添加 VLESS Reality 节点:
proxies: - name: "Reality-US" type: vless server: your.server.ip port: 8443 uuid: f6b7d3e2-1a2b-3c4d-5e6f-7a8b9c0d1e2f network: tcp tls: true udp: true flow: xtls-rprx-vision servername: www.apple.com reality-opts: public-key: "3Km..." # Xray 生成的公钥 short-id: "a1b2c3d4e5f6a7b8" client-fingerprint: chromeVMess + WS + TLS 节点:
proxies: - name: "VMess-CDN" type: vmess server: your.domain.com # 或 Cloudflare CDN IP port: 443 uuid: f6b7d3e2-1a2b-3c4d-5e6f-7a8b9c0d1e2f alterId: 0 cipher: auto tls: true network: ws ws-opts: path: /ray headers: Host: your.domain.com skip-cert-verify: false5.2 sing-box(全平台)
{ "outbounds": [ { "type": "vless", "tag": "Reality-US", "server": "your.server.ip", "server_port": 8443, "uuid": "f6b7d3e2-1a2b-3c4d-5e6f-7a8b9c0d1e2f", "flow": "xtls-rprx-vision", "tls": { "enabled": true, "server_name": "www.apple.com", "utls": { "enabled": true, "fingerprint": "chrome" }, "reality": { "enabled": true, "public_key": "3Km...", "short_id": "a1b2c3d4e5f6a7b8" } } } ]}六、常见故障排查
| 症状 | 可能原因 | 解决方案 |
|---|---|---|
| 服务无法启动 | 配置文件 JSON 语法错误 | xray run -c config.json 手动运行看报错 |
| 端口被占用 | 其他进程占用同端口 | ss -tlnp | grep 8443 查看并结束占用进程 |
| 客户端连接超时 | 服务器防火墙未放行端口 | 检查 ufw 和云服务商安全组双重防火墙 |
| Reality 连接失败 | pubkey / shortId 填错 | 确认客户端用的是 Public key,不是 Private key |
| WS 连接报 400/404 | Nginx location path 与客户端不一致 | 检查 Nginx /ray 路径是否与客户端 path 一致 |
| CDN 模式下连接慢 | Cloudflare 未套 WebSocket 支持 | CF Dashboard → Speed → Optimization → 开启 WebSockets |
| 流媒体解锁失败 | VPS IP 被识别为数据中心 | 换用支持流媒体的 VPS 服务商(如 DMIT),或用机场节点 |
# 实用排查命令# 查看 Xray 运行日志journalctl -u xray -f --no-pager
# 测试本地 Xray 是否监听ss -tlnp | grep xray
# 测试 Nginx 配置语法nginx -t
# 从客户端测试 WS 端口连通性curl -I https://your.domain.com/ray -H "Upgrade: websocket" -H "Connection: Upgrade"
# 查看服务器访问日志tail -f /var/log/nginx/access.logtail -f /var/log/xray/access.log七、安全加固建议
# 1. 修改 SSH 端口(减少暴力破解)vim /etc/ssh/sshd_config# Port 22 → Port 22222systemctl restart sshd
# 2. 禁止 root SSH 登录# PermitRootLogin no# 改为用普通用户 + sudo
# 3. 安装 Fail2ban(自动封禁暴力破解 IP)apt install -y fail2bansystemctl enable fail2ban
# 4. 定期更新 Xraybash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
# 5. 定期更换 UUID 和密钥对(每 3-6 个月)相关文章:
- 2026 代理客户端深度横评:Clash Verge Rev / sing-box / Shadowrocket / Stash / Hiddify
- mihomo(Clash Meta)完全配置指南:TUN + Docker + 旁路由
- sing-box 全平台使用教程:新一代通用代理平台配置指南
- Cloudflare Workers 实战:免费搭建反向代理 + 订阅转换
- 2026年高性价比机场推荐(不想自建节点时的选择)
本文所有配置均为技术学习目的,请遵守当地相关法律法规。Xray 版本更新频繁,配置字段以官方 XTLS/Xray-core Wiki 为准。
V2Ray / VMess 完全配置指南 2026:服务端部署 + 客户端配置 + TLS + CDN 隐匿全攻略
https://971918.xyz/posts/proxy-tools/v2ray-vmess-config-guide/