用自己的 REALITY 服务端
正常路径是
sudo bx server up:它在 VPS 上装好 REALITY + hysteria2、选好 SNI 并检查证书大小,最后打印 整条sudo bx setup …命令,不需要看这一篇。见服务端。
这一篇只给已经有、或想自己维护一个 sing-box(或 Xray)VLESS-REALITY 服务端的人:怎么配,以及怎么拼出一条
vless:// 链接交给 bx setup。客户端这边的 sing-box 已经内嵌在 bx 里,不用装。
选端口和 SNI
- 端口用 443。 REALITY 伪装成访问真实网站的 HTTPS,落在 443 最自然;换到不常见的端口反而更显眼。 唯一的约束是防火墙:服务器上的 ufw 和云服务商的安全组都要放行 443。443 已经被真实的网站占用时,才换一个已放行的高端口。
- 借用的 SNI 挑支持 TLS 1.3 + X25519、证书链又不大(约 4.5KB 以内)的站。
www.cloudflare.com(bx 的默认)、www.apple.com、dl.google.com、addons.mozilla.org都可以。不要用www.microsoft.com:它的证书链太大, 握手必定失败。
在 VPS 上检查一个候选站点:
# 支持 TLS 1.3 与 X25519?
openssl s_client -connect www.cloudflare.com:443 -servername www.cloudflare.com -tls1_3 </dev/null 2>/dev/null | grep -iE 'TLSv1.3|X25519'
# 证书链有多大(越小越稳)
openssl s_client -connect www.cloudflare.com:443 -servername www.cloudflare.com -tls1_3 -showcerts </dev/null 2>/dev/null | awk '/BEGIN CERT/,/END CERT/' | wc -c
装 sing-box 并生成密钥
服务器是普通的 Ubuntu / Debian 时,用 sing-box 官方的安装脚本:
curl -fsSL https://sing-box.app/install.sh | bash
sing-box version
sing-box generate uuid # → VLESS UUID
sing-box generate reality-keypair # → PrivateKey(写进服务端)/ PublicKey(写进链接)
sing-box generate rand --hex 8 # → short_id
服务端配置
/etc/sing-box/config.json(最小配置:一个 VLESS-REALITY 入站 + 一个直连出站):
{
"log": { "level": "info", "timestamp": true },
"inbounds": [{
"type": "vless",
"tag": "vless-reality-in",
"listen": "::",
"listen_port": 443,
"users": [{ "name": "primary", "uuid": "REPLACE_UUID", "flow": "xtls-rprx-vision" }],
"tls": {
"enabled": true,
"server_name": "www.cloudflare.com",
"reality": {
"enabled": true,
"handshake": { "server": "www.cloudflare.com", "server_port": 443 },
"private_key": "REPLACE_PRIVATE_KEY",
"short_id": ["REPLACE_SHORT_ID"]
}
}
}],
"outbounds": [{ "type": "direct", "tag": "direct" }]
}
sing-box check -c /etc/sing-box/config.json && echo OK
systemctl enable --now sing-box
ufw allow 443/tcp # 云服务商的安全组也要放行
拼链接,交给 bx
vless://<UUID>@<VPS 的 IP 或域名>:443?security=reality&pbk=<PublicKey>&sid=<short_id>&sni=www.cloudflare.com&flow=xtls-rprx-vision&fp=chrome
必填的是 UUID、地址、端口、security=reality、pbk、sid、sni;flow 默认 xtls-rprx-vision,fp 默认 chrome。
Xray 服务端同样按这几项拼。
在电脑上:
sudo bx setup 'vless://…' # 写配置并检测连通,不打开保护
bx up
bx status # Tunnel healthy
链接里有明文凭据,当密码对待。客户端连上后,服务端 journalctl -u sing-box -f 能看到入站连接。
连不上时
- 服务端日志一条连接都没有、客户端超时:端口没放行。ufw 和云安全组都要放行。
- 端口通,但握手失败(服务端日志
processed invalid connection,客户端 EOF):先怀疑借用 SNI 的证书链太大, 换一个证书链小的站点,通常不是密钥或网络的问题。 - 在 OpenWrt 路由器上测连通:BusyBox 的
ash不支持/dev/tcp,用curl或nc,否则结果全是假阴性。