VPS 自建代理节点实战:VLESS-REALITY + Hysteria2 + 443 端口复用

从选机器到跑满速:用 sing-box 自建 VLESS-REALITY 节点,加 Hysteria2 做 UDP 备胎,再用 nginx L4 让代理、网站、订阅共用一个 443 端口。附 GFW 端口封锁的实测结论和完整踩坑。

一、为什么不买机场

1
2
❌ 机场: 说跑路就跑路 ✗ 节点共享、高峰期卡成 PPT ✗ 你的流量从别人的机器过、日志归别人
✅ 自建: 独享带宽 ✅ 链路自己掌握 ✅ 换个 IP 重开就行 ✅ 成本约一杯咖啡/月

代价:得自己动手一次。本文就是把这一次动手写完整。

二、选机器:先想清楚三件事

关注点建议
地区香港/日本/新加坡延迟低;美国带宽便宜但延迟高 ⚠️
带宽30Mbps 够日常看 1080P;要看 4K 建议 100Mbps+ ✅
线路★ 最容易被忽略的一项 ⚠️ 同是香港,CN2 GIA 和普通国际线路体验差好几倍
端口★★ 必须确认 443 可用(原因见第五节)⚠️

⚠️ 买之前先看服务商是否允许「网络加速/代理」用途,有些 ToS 明文禁止 ✗ (本文只讲技术实现,具体合规请自行判断 ⚠️)

三、装 sing-box

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# 官方一键脚本
curl -fsSL https://sing-box.app/install.sh | sudo bash

# 或者手动下二进制
curl -fsSL -o sb.tar.gz $(curl -s https://api.github.com/repos/SagerNet/sing-box/releases/latest \
  | grep -oE '"browser_download_url": "[^"]*linux-amd64[^"]*"' | head -1 | cut -d'"' -f4)
tar xzf sb.tar.gz --strip-components=1 sing-box-*/sing-box
sudo mv sing-box /usr/local/bin/ && sudo chmod +x /usr/local/bin/sing-box

sing-box version    # 确认装好,本文实测 1.14.2 支持 hysteria2 ✅

四、VLESS-REALITY 服务端(主力,走 TCP 443)

REALITY 是什么:不需要自己的域名和证书,借用真实大站的 TLS 指纹做伪装 ✅ 从外面看,你的节点就是一次访问 www.cloudflare.com 的普通 HTTPS 请求 ✅

4.1 生成密钥和 UUID

1
2
3
4
5
6
7
8
# 生成 UUID
sing-box generate uuid

# 生成 REALITY 密钥对(记下 PrivateKey 和 PublicKey)
sing-box generate reality-keypair
# 输出:
#   PrivateKey: <私钥>     ← 写在服务端配置里
#   PublicKey:  <公钥>     ← 写在客户端配置里

4.2 服务端配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// /etc/sing-box/conf/VLESS-REALITY-8443.json
{
  "log": { "level": "warn" },
  "inbounds": [
    {
      "type": "vless",
      "tag": "vless-in",
      "listen": "127.0.0.1",          // ★ 只绑内网,对外由 nginx L4 转发(见第五节)
      "listen_port": 8443,
      "users": [
        {
          "uuid": "<你的UUID>",
          "flow": "xtls-rprx-vision"   // ★ REALITY 建议开这个流控
        }
      ],
      "tls": {
        "enabled": true,
        "server_name": "www.cloudflare.com",   // ★ 伪装的目标域名
        "reality": {
          "enabled": true,
          "handshake": {
            "server": "www.cloudflare.com",
            "server_port": 443
          },
          "private_key": "<你的REALITY私钥>",
          "short_id": [""]              // ⚠️ sing-box 要【字符串】,写成 [""] 这个数组是对的 ✅
        }
      }
    }
  ],
  "outbounds": [{ "type": "direct" }]
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# /etc/systemd/system/sing-box.service(如果用官方脚本装,它已经建好了)
[Unit]
Description=sing-box service
After=network.target nss-lookup.target

[Service]
User=root
ExecStart=/usr/local/bin/sing-box run -c /etc/sing-box/conf/VLESS-REALITY-8443.json
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
1
2
3
sudo systemctl enable --now sing-box
sudo systemctl status sing-box --no-pager | head -5
sudo ss -tlnp | grep 8443

五、★★ 最关键的部分:443 端口复用

5.1 为什么节点必须占 443

实测结论(重要):

1
2
3
4
5
6
7
8
在一台香港 VPS 上测 8443 端口:
  · 本机连自己公网 IP:8443   ✅ 通
  · 防火墙 / 云安全组        ✅ 全放行
  · 国内从外部连 8443        ✗ 不通!
  · 国内从外部连 443 / 80    ✅ 通

⇒ GFW 会阻断(或严重 QoS)非标准端口
⇒ 代理节点想稳定,【必须占用 443】✗ 没有别的办法

5.2 但 443 上还想跑网站怎么办 —— nginx L4 分流

关键点:TLS ClientHello 里的 SNI 是明文的 ✅ nginx 只读它做纯 TCP 转发,不做 TLS 解密 → REALITY 的指纹完全不受影响 ✅

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# /etc/nginx/stream-reality.conf
stream {
    map $ssl_preread_server_name $backend {
        # ★ 伪装用的域名 → 送给 sing-box(REALITY 自己处理握手)
        www.cloudflare.com   127.0.0.1:8443;
        # 其它所有域名 → 送给网站服务
        default              127.0.0.1:8448;
    }
    server {
        listen          443;
        listen          [::]:443;
        ssl_preread     on;             # ★ 只读明文 SNI,不解密
        proxy_pass      $backend;
        proxy_timeout   300s;
        proxy_connect_timeout 10s;
    }
}
1
2
3
4
# nginx.conf 里挂上
stream {
    include /etc/nginx/stream-reality.conf;
}
1
2
sudo nginx -t && sudo systemctl reload nginx
sudo ss -tlnp | grep ':443'      # nginx 应该绑在 0.0.0.0:443 ✅

验证两条链路都没坏:

1
2
3
4
5
# ① 节点链路(应该拿到 403 或正常握手,不是连接失败)
curl -sI --max-time 10 https://<你的IP>/ -H "Host: www.cloudflare.com" | head -3

# ② 网站链路(用你的域名)
curl -sI --max-time 10 https://your-domain.example.com/ | head -3

5.3 ⚠️ 顺便说一个死路

1
2
3
4
Lucky 这类面板自带的「SNI 分流」功能 —— 实测【做不到 L4 透传】✗
现象:配好后 openssl s_client -servername <节点域名> 拿不到证书,curl 返回 000
原因:它在分流时自己做了 TLS 终止 → REALITY 握手直接失败 ✗
⇒ 要保 REALITY 就必须用 nginx 的 stream + ssl_preread ✅

六、Hysteria2 备胎(走 UDP 443)

TCP 443 被占用了,但 UDP 443 是另一个独立端口 ✅ 可以同时用 ✅

Hysteria2 基于 QUIC,弱网、丢包环境下比 TCP 快得多 ✅ 适合做备胎 ✅

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// 追加到 inbounds 数组里
{
  "type": "hysteria2",
  "tag": "hy2-in",
  "listen": "::",
  "listen_port": 443,                    // UDP 443(和 TCP 443 不冲突 ✅)
  "users": [{ "password": "<你的密码>" }],
  "tls": {
    "enabled": true,
    "server_name": "your-domain.example.com",
    "certificate_path": "/etc/letsencrypt/live/your-domain.example.com/fullchain.pem",
    "key_path":         "/etc/letsencrypt/live/your-domain.example.com/privkey.pem",
    "alpn": ["h3"]
  }
}

⚠️ Hysteria2 需要真证书(不像 REALITY 能白嫖)✗ 用 acme.sh / certbot 签一张,泛域名更省事 ✅

1
2
3
4
5
6
sudo systemctl restart sing-box
sudo ss -ulnp | grep 443      # 确认 UDP 443 在听 ✅

# 国内实测(本机 curl 走 cloudflare trace)
curl -s --max-time 15 https://www.cloudflare.com/cdn-cgi/trace
# 期望能看到 colo=HKG(香港落地 ✅)+ 耗时正常 ✅

七、客户端配置

7.1 节点分享链接

1
vless://<UUID>@<你的域名>:443?encryption=none&security=reality&flow=xtls-rprx-vision&type=tcp&sni=www.cloudflare.com&pbk=<公钥>&fp=chrome#节点名

参数说明:

参数值注意
securityreality★
sni伪装域名必须和服务端 server_name 一致 ✗
pbk公钥★ 服务端配的是私钥,客户端填公钥 ⚠️ 别搞反
fpchrome指纹伪装 ✅
flowxtls-rprx-vision★ 和服务端一致

7.2 mihomo / Clash 配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
proxies:
  - name: "⭐vps-vless-reality"
    type: vless
    server: your-domain.example.com
    port: 443
    uuid: <你的UUID>
    network: tcp
    tls: true
    udp: true
    flow: xtls-rprx-vision
    servername: www.cloudflare.com
    reality-opts:
      public-key: <你的REALITY公钥>
      short-id: ""
    client-fingerprint: chrome

  - name: "⭐vps-hysteria2"
    type: hysteria2
    server: your-domain.example.com
    port: 443
    password: <你的hy2密码>
    sni: your-domain.example.com
    alpn: [h3]
    skip-cert-verify: false

⚠️ 新版 mihomo 移除了全局 global-client-fingerprint ✗ 改成每个节点单独写 client-fingerprint ✅

八、自建订阅站(可选)

节点多了(自建 + 机场聚合),用订阅一次性下发最省事 ✅

1
2
3
4
# 最小实现:一个 nginx 静态站 + 定期生成的文件
sudo mkdir -p /var/www/sub/<随机路径>
# 把 clash.yaml 和 base64 的 sub.txt 放进去
# 再用 nginx 挂一个域名 + 泛域名证书 ✅
1
2
# 定时重生成(crontab)
0 4 * * * /path/to/merge_nodes.sh    # 每天早上重新聚合一次 ✅

⚠️ 订阅路径就是访问凭据 —— 路径里放一段随机串,别外发 ✗

九、实测证据链

1
2
3
4
5
✅ 节点(TCP 443)      → HTTP 403 | 5028 字节 | 0.26s(REALITY 正常响应)
✅ Hysteria2(UDP 443) → HTTP 200 | 0.25s | colo=HKG
✅ 网站(同 443 端口)  → HTTP 200 | 0.26s(nginx L4 分流没搞坏 ✅)
✅ 经代理出口          → ip=<VPS IP> | colo=HKG ✅
✅ 证书               → CN=example.com | SAN: *.example.com ✅

十、踩坑清单

#现象原因解决
1★ 节点国内完全连不上用了非标端口 ✗换 443(第五节)
2客户端握手失败REALITY 公/私钥搞反 ✗服务端 private_key,客户端 public-key
3握手失败sni 和 server_name 不一致 ✗两端改成完全一样
4sing-box 起不来short_id 类型写错 ✗用数组 [""]
5网站和节点互相影响分流顺序写错 ✗map 里节点域名写前面,default 兜底
6nginx 不认 http2 on;老版本 nginx(1.24 及以下)✗用旧写法 listen 443 ssl http2;
7hy2 连不上证书路径不对 / 没签真证书 ✗Hysteria2 必须真证书
8客户端报客户端指纹错新版 mihomo 移除全局字段 ✗每节点单独写 client-fingerprint
9订阅拉不到客户端不支持 / 被缓存 ✗检查客户端内核(要 mihomo 系 ✅)
10改完 ssh 掉线动防火墙把自己关了 ✗改防火墙前先确认放行了 22 ⚠️⚠️

十一、小结

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
架构:
  用户 ──TCP443──► nginx L4 (ssl_preread)
                     ├─ SNI=伪装域名  → 127.0.0.1:8443  sing-box VLESS-REALITY  ✅ 主力
                     └─ default        → 127.0.0.1:8448  网站服务 ✅
  用户 ──UDP443──► sing-box Hysteria2 ✅ 备胎(弱网/丢包时更快)

三条铁律:
  ① 节点必须占 443(GFW 封非标端口,实测过 ✗)
  ② REALITY 要保指纹,分流必须是 L4 纯转发,不能解密 ✗
  ③ 双协议(TCP 443 + UDP 443)互不影响,全都要上 ✅

本文所有配置与结论均在真实 VPS 环境验证过。