安装 xray

bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install

生成 uuid

xray uuid

输出示例:8653f110-61d8-4363-8c5c-1224fa1bc18b

生成 Reality 密钥对

# 生成 X25519 公私钥对
xray x25519

输出示例:

PrivateKey: CDQnBSjLb45viCBJTVt7n5ZmImy80NW7ovdlqRPi2k
Password (PublicKey): nZY-gSIXu1N6lxpxzodqf_hc08UQBEkqiLNN5hv8TQ
Hash32: VXqfOosY-X1NwQTfMx7Vfd3kxlRvvxJYM5Vrac9WNJU
**重要:请保存好这两个密钥!**

- Private key(私钥):配置在服务器端
- Password(原 Public Key -> 公钥):配置在客户端

生成 Short ID

# 生成 16 位十六进制 short_id
openssl rand -hex 8

输出示例:a7c581a4431eca74

  • 编辑 Xray 配置文件 vim /usr/local/etc/xray/config.json
 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
33
34
35
36
37
38
39
40
41
42
43
{
  "log": {
    "loglevel": "info"
  },
  "inbounds": [
    {
      "tag": "VLESS-Vision-REALITY",
      "listen": "::",
      "port": 443,
      "protocol": "vless",
      "settings": {
        "clients": [
          {
            "id": "8653f110-61d8-4363-8c5c-1224fa1bc18b", // 填入刚才生成的 UUID
            "flow": "xtls-rprx-vision"
          }
        ],
        "decryption": "none"
      },
      "streamSettings": {
        "network": "raw",
        "security": "reality",
        "realitySettings": {
          "show": false,
          "dest": "www.microsoft.com:443", // 目标网站:端口
          "serverNames": ["www.microsoft.com"], // 目标网站域名
          "privateKey": "CDQnBSjLb45viCBJTVt7n5ZmImy80NW7ovdlqRPi2k", // 填入刚才生成的 Private Key
          "shortIds": ["a7c581a4431eca74"] // 填入 8 到 16 位的 16 进制字符串(随便写)
        }
      }
    }
  ],
  "outbounds": [
    {
      "tag": "direct",
      "protocol": "freedom"
    },
    {
      "tag": "block",
      "protocol": "blackhole"
    }
  ]
}

启动服务

1
2
# 检查配置文件语法是否正确
xray run -test -config /usr/local/etc/xray/config.json

输出示例:

Xray 26.3.27 (Xray, Penetrates Everything.) d2758a0 (go1.26.1 linux/amd64) A unified platform for anti-censorship. 2026/05/05 04:44:43.340031 [Info] infra/conf/serial: Reading config: &{Name:/usr/local/etc/xray/config.json Format:json} Configuration OK.

1
2
3
4
5
6
7
8
# 重启 Xray 服务
systemctl restart xray

# 设置开机自启
systemctl enable xray

# 查看服务状态
systemctl status xray

客户端如何连接?

客户端推荐:

  • Windows/Linux/macOS: v2rayN
  • Android: v2rayNG
  • iOS: Shadowrocket

在你的客户端中填入以下关键参数:

  • 协议: VLESS
  • 地址/IP: 你的 VPS 公网 IP
  • 端口: 443
  • UUID: 你生成的 UUID
  • 流控 (Flow): xtls-rprx-vision
  • 传输层安全 (TLS): REALITY
  • SNI: www.microsoft.com (必须与服务端 dest 一致)
  • PublicKey: 你生成的 Public Key (公钥)
  • ShortId: 你在配置中写的 shortId
  • 指纹 (Fingerprint): chrome 或 firefox

选择目标网站

Reality 需要一个目标网站(dest/target)来进行伪装。这个网站需要满足以下条件:

  • ✅ 支持 TLS 1.3
  • ✅ 支持 X25519 密钥交换
  • ✅ 支持 HTTP/2(h2)
  • ⭐️ 加分项:网站服务器物理距离和你的VPS近 (IP 相近)
  • ⭐️ 加分项:网站支持 OCSP Stapling
  • 选取方法参考:https://github.com/XTLS/Xray-core/issues/2005#issuecomment-1538294415

代中代

實現「客戶端 → 韓國伺服器 A → 香港伺服器 B → 目標網站」的鏈式代理(也就是俗稱的「鏈接代理」或「前置代理 + 落地代理」),只需要修改伺服器 A 和伺服器 B 的 Xray 設定檔。

伺服器 A 的 Xray 設定檔:

 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
  "log": {
    "loglevel": "info"
  },
  "inbounds": [
    {
      "tag": "VLESS-Vision-REALITY",
      "listen": "::",
      "port": 4443,
      "protocol": "vless",
      "settings": {
        "clients": [
          {
            "id": "57748eb4-761c-4609-a7f6-2dbb4240a163",
            "flow": "xtls-rprx-vision"
          }
        ],
        "decryption": "none"
      },
      "streamSettings": {
        "network": "tcp", //改成 tcp
        "security": "reality",
        "realitySettings": {
          "show": false,
          "dest": "www.onedc.com:443",
          "serverNames": ["www.onedc.com"],
          "privateKey": "qHn-Yaksk5vuCPcgWf47M35cdGnsdMfWgqgwglf4",
          "shortIds": ["a7c581a4431eca74"]
        }
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "vless",
      "settings": {
        "vnext": [
          {
            "address": "18.162.214.xx", // 伺服器 B 的 IP
            "port": 443,
            "users": [
              {
                "id": "e5015ed1-1a5b-40f0-9bc6-7ad37a9a11", // 伺服器 B 的 UUID
                "encryption": "none",
                "flow": "xtls-rprx-vision"
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "tcp",
        "security": "reality",
        "realitySettings": {
          //"show": false,
          //"dest": "www.onedc.com:443",
          "serverName": "www.onedc.com", // 伺服器 A 的域名 ,outbound 必須是單數的 serverName 字串
          "publicKey": "Malc0hqESp5zc6oYMiltzhA18OJZKY3HtpHVvnmis", // 伺服器 B 的公鑰
          "shortId": "940e06c9610464c8" // outbound 必須是單數的 shortId 字串
          // 这里要填 B 的 Reality 参数(公钥、shortId、serverName 等)
        }
      },
      "tag": "out-to-b"
    },
    {
      "protocol": "freedom",
      "tag": "direct"
    },
    {
      "protocol": "blackhole",
      "tag": "block"
    }
  ],
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "inboundTag": ["VLESS-Vision-REALITY"],
        "outboundTag": "out-to-b"
      }
    ]
  }
}