安装 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