Xray
Xray-core 是由 XTLS 项目组开发的高性能代理核心程序,项目地址为 github.com/XTLS/Xray-core。它是 V2Ray 的增强分支,在完整保留 V2Ray 功能的基础上,引入了 XTLS 流控技术、VLESS 协议、Reality 扩展等重要创新,是目前 VLESS + Reality 方案的原生最佳实现。
核心特性
- VLESS + Reality 原生支持:Reality 扩展由 Xray 团队设计,在 Xray 中实现最完整、更新最及时
- XTLS 流控:独创的 XTLS 技术,通过直接拼接内外层 TLS 数据流消除双重加密开销,实现极高的传输性能
- 全协议支持:VMess、VLESS、Trojan、Shadowsocks、Shadowsocks 2022、Hysteria 2、WireGuard 等主流协议均已支持
- 灵活的路由系统:基于域名、IP、端口、协议、进程名等多维度的精细路由规则
- 回落机制(Fallback):服务端收到非预期流量时,自动转发给后端服务,有效对抗主动探测
- 多入站/多出站架构:单实例可同时运行多个监听接口和多个出站节点
- 统计 API:内置流量统计,可按用户统计入出站流量
- DNS 分流:内置 DNS 处理,支持按规则将不同域名的 DNS 查询路由到不同的解析服务器
与 V2Ray / V2Fly 的关系
Xray-core 与 V2Ray / V2Fly 在架构上高度相似,均采用相同的配置格式(JSON)和相近的设计理念,但存在以下关键差异:
| 对比维度 | Xray-core | V2Fly(V2Ray 社区版) |
|---|---|---|
| XTLS 流控 | 原创支持(xtls-rprx-vision) | 不支持 |
| Reality 扩展 | 原创支持,功能最完整 | 不支持(或支持有限) |
| VLESS 协议 | 原创设计,支持最完整 | 支持,但部分新特性滞后 |
| Hysteria 2 | 支持 | 不支持 |
| 配置格式兼容性 | 与 V2Ray 高度兼容 | V2Ray 原版格式 |
| 更新频率 | 活跃 | 较活跃 |
| 主要维护者 | XTLS 项目组 | V2Fly 社区 |
总结:如果你自建节点,尤其是使用 VLESS + Reality 方案,Xray-core 是首选;如果只是使用 VMess + WebSocket + TLS 等传统方案,V2Fly 也完全胜任。
安装
Linux(推荐:官方安装脚本)
Xray 官方提供了一键安装脚本,支持 Debian / Ubuntu / CentOS 等主流发行版:
# 安装最新稳定版
bash <(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh) install
安装完成后:
- 二进制文件位于:
/usr/local/bin/xray - 配置文件目录:
/usr/local/etc/xray/ - 主配置文件:
/usr/local/etc/xray/config.json - systemd 服务单元:已自动创建,服务名为
xray - GeoIP / GeoSite 数据文件:
/usr/local/share/xray/
安装特定版本(如 v1.8.24):
bash <(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh) install -version v1.8.24
更新到最新版:
bash <(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh) install
卸载:
bash <(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh) remove
Linux(手动安装)
从 GitHub Releases 下载对应系统和架构的预编译文件:
# 以 Linux amd64 为例
wget https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-64.zip
unzip Xray-linux-64.zip
chmod +x xray
mv xray /usr/local/bin/xray
# 下载 GeoIP 和 GeoSite 数据文件
mkdir -p /usr/local/share/xray
wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat -O /usr/local/share/xray/geoip.dat
wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat -O /usr/local/share/xray/geosite.dat
验证安装:
xray version
macOS
方法一:Homebrew
brew install xray
方法二:手动下载
从 GitHub Releases 下载 Xray-macos-64.zip(Intel)或 Xray-macos-arm64-v8a.zip(Apple Silicon),解压后移动到 PATH 中。
Windows
从 GitHub Releases 下载 Xray-windows-64.zip,解压后得到 xray.exe。
将其添加到系统 PATH,或者直接使用基于 Xray 的 GUI 工具(如 v2rayN),GUI 工具会自动管理 Xray 核心的下载和更新。
主流 GUI 客户端
以下 GUI 工具均以 Xray-core 为底层核心之一:
| 客户端 | 平台 | 特点 | 项目地址 |
|---|---|---|---|
| v2rayN | Windows / macOS / Linux | 功能最全面的老牌客户端,支持 Xray 和 sing-box 双核心 | GitHub |
| v2rayNG | Android | Android 平台经典选择,Xray 内核 | GitHub |
| Hiddify | Windows / macOS / Linux / Android | 界面现代,同时支持 sing-box 内核 | GitHub |
关于 v2rayN 和 Xray
v2rayN 是目前 Windows 平台上使用 Xray-core 的最主流 GUI 工具。它同时支持 Xray-core 和 sing-box 两个核心,可以在设置中选择使用哪个核心处理连接。对于需要使用 VLESS + Reality 的 Windows 用户,v2rayN + Xray-core 是首选组合。
内置工具命令
Xray 提供了一些内置的实用工具,常用于节点配置:
# 生成新的 UUID
xray uuid
# 生成 X25519 密钥对(用于 Reality)
xray x25519
# 生成随机短 ID(用于 Reality)
xray rand -l 8 # 生成 8 字节(16 位十六进制)的随机字符串
# 验证配置文件语法
xray run -test -config /usr/local/etc/xray/config.json
# 运行配置文件中指定的程序(非 run 模式,用于调试)
xray run -config /usr/local/etc/xray/config.json
配置文件结构
Xray 使用 JSON 格式的配置文件,与 V2Ray 兼容。完整的配置文件由以下顶层字段构成:
{
"log": { ... }, // 日志配置
"api": { ... }, // API 接口(可选)
"dns": { ... }, // DNS 配置
"routing": { ... }, // 路由规则
"policy": { ... }, // 连接策略(超时、统计等)
"inbounds": [ ... ], // 入站配置
"outbounds": [ ... ], // 出站配置
"transport": { ... }, // 全局传输层配置(可选)
"stats": { ... }, // 流量统计(可选)
"reverse": { ... }, // 反向代理(可选)
"fakedns": { ... }, // FakeDNS(可选)
"observatory": { ... } // 节点健康检测(可选)
}
服务端部署教程
教程一:VLESS + Reality(推荐,无需域名)
这是目前最推荐的自建节点方案,无需域名和证书,抗检测能力极强。
前置条件:
- 一台具有公网 IP 的 VPS
- 服务器已开放 TCP 443 端口
- 已安装 Xray-core(使用上文的官方安装脚本)
第一步:生成密钥对和 UUID
# 生成 Reality 所需的 X25519 密钥对
xray x25519
输出示例:
Private key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Public key: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
# 生成用户 UUID
xray uuid
输出示例:
9f67b8a2-3c1d-4e5f-a6b7-c8d9e0f1a2b3
# 生成 shortId(8 字节随机十六进制字符串)
openssl rand -hex 8
第二步:编写服务端配置
编辑 /usr/local/etc/xray/config.json:
{
"log": {
"loglevel": "warning"
},
"inbounds": [
{
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "9f67b8a2-3c1d-4e5f-a6b7-c8d9e0f1a2b3",
"flow": "xtls-rprx-vision"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {
"show": false,
"dest": "www.apple.com:443",
"serverNames": [
"www.apple.com"
],
"privateKey": "your-private-key-here",
"shortIds": [
"a1b2c3d4e5f6g7h8"
]
}
},
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls", "quic"]
}
}
],
"outbounds": [
{
"protocol": "freedom",
"tag": "direct"
},
{
"protocol": "blackhole",
"tag": "block"
}
],
"routing": {
"domainStrategy": "AsIs",
"rules": [
{
"type": "field",
"ip": ["geoip:private"],
"outboundTag": "block"
}
]
}
}
关键字段说明:
| 字段 | 说明 |
|---|---|
id | 用户 UUID,客户端必须填写相同的值 |
flow | 流控方式,使用 xtls-rprx-vision |
dest | Reality 握手的目标服务器,必须是真实存在的 TLS 1.3 网站 |
serverNames | 客户端 SNI 列表,客户端配置的 serverName 必须在此列表中 |
privateKey | 服务端私钥(保密) |
shortIds | 短 ID 列表,客户端配置的 shortId 必须在此列表中 |
第三步:启动服务
systemctl enable xray
systemctl start xray
systemctl status xray
# 查看实时日志
journalctl -u xray -f
第四步:开放防火墙
# UFW
ufw allow 443/tcp
# iptables
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
第五步:客户端配置参数
将以下信息提供给客户端:
| 参数 | 值 |
|---|---|
| 服务器地址 | 你的服务器 IP |
| 端口 | 443 |
| 协议 | VLESS |
| UUID | 你配置的 UUID |
| 流控(flow) | xtls-rprx-vision |
| 传输方式 | tcp |
| 安全类型 | reality |
| SNI(serverName) | www.apple.com |
| 公钥(publicKey) | 你生成的 Public key |
| shortId | 你配置的 shortId |
| 指纹(fingerprint) | chrome |
教程二:VLESS + XTLS-Vision + TLS(需要域名,性能最高)
适合已有域名和证书的用户,是 TCP 直连方案中性能最优的配置。
前置条件:
- 一个指向服务器 IP 的域名(已完成 DNS A 记录解析)
- 服务器已开放 TCP 80 和 443 端口
- 已安装 Xray-core 和 acme.sh
第一步:申请 TLS 证书
# 安装 acme.sh
curl https://get.acme.sh | sh
source ~/.bashrc
# 申请证书(HTTP 验证,确保 80 端口可访问)
~/.acme.sh/acme.sh --issue -d your.domain.com --webroot /var/www/html
# 安装证书到 Xray 目录
mkdir -p /usr/local/etc/xray/certs
~/.acme.sh/acme.sh --install-cert -d your.domain.com \
--cert-file /usr/local/etc/xray/certs/cert.pem \
--key-file /usr/local/etc/xray/certs/key.pem \
--reloadcmd "systemctl restart xray"
关于 DNS 验证
如果 80 端口已被占用,可以改用 DNS 验证方式申请证书(需要在域名 DNS 管理面板添加 TXT 记录):
~/.acme.sh/acme.sh --issue -d your.domain.com --dns \
--yes-I-know-dns-manual-mode-enough-go-ahead-please
然后按照提示添加 DNS TXT 记录,等待 DNS 生效后运行验证命令。
第二步:配置服务端
{
"log": {
"loglevel": "warning"
},
"inbounds": [
{
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "your-uuid-here",
"flow": "xtls-rprx-vision"
}
],
"decryption": "none",
"fallbacks": [
{
"dest": 8080,
"xver": 1
}
]
},
"streamSettings": {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"minVersion": "1.3",
"certificates": [
{
"certificateFile": "/usr/local/etc/xray/certs/cert.pem",
"keyFile": "/usr/local/etc/xray/certs/key.pem"
}
]
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"tag": "direct"
}
]
}
第三步:配置回落 Web 服务(Nginx)
# 安装 Nginx
apt install nginx
# 创建网站根目录和示例页面
mkdir -p /var/www/html
echo "<html><body><h1>Welcome</h1></body></html>" > /var/www/html/index.html
Nginx 配置(/etc/nginx/sites-enabled/default):
server {
listen 8080;
server_name your.domain.com;
set_real_ip_from 127.0.0.1;
real_ip_header X-Real-IP;
root /var/www/html;
index index.html;
access_log /var/log/nginx/access.log;
}
systemctl enable nginx
systemctl start nginx
教程三:VMess + WebSocket + TLS(可过 CDN)
适合需要通过 Cloudflare 等 CDN 中转的场景,服务器 IP 被封时仍可使用。
前置条件:
- 一个托管在 Cloudflare 的域名(已将流量代理开启,即"橙色云")
- 服务器已安装 Xray-core 和 Nginx(或 Caddy)
- 有效的 TLS 证书
服务端配置(Xray 监听本地端口):
{
"inbounds": [
{
"port": 10086,
"listen": "127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "your-uuid-here",
"alterId": 0
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/your-secret-path-here"
}
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
]
}
Nginx 反向代理配置:
server {
listen 443 ssl;
server_name your.domain.com;
ssl_certificate /usr/local/etc/xray/certs/cert.pem;
ssl_certificate_key /usr/local/etc/xray/certs/key.pem;
ssl_protocols TLSv1.2 TLSv1.3;
location /your-secret-path-here {
proxy_pass http://127.0.0.1:10086;
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;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
}
location / {
root /var/www/html;
}
}
server {
listen 80;
server_name your.domain.com;
return 301 https://$host$request_uri;
}
Cloudflare 设置:
- 在 Cloudflare DNS 面板中,确认域名的 A 记录的代理状态为"已代理"(橙色云图标)
- 在 SSL/TLS 设置中,将加密模式设为 Full(严格)(不要选 Flexible,否则会出现重定向循环)
- 确认 WebSocket 支持已在 Network 设置中启用
教程四:Trojan + TLS(简洁的 TLS 伪装)
配置简洁,流量伪装为 HTTPS,适合不需要 CDN 中转的 TLS 伪装场景。
{
"inbounds": [
{
"port": 443,
"protocol": "trojan",
"settings": {
"clients": [
{
"password": "your-strong-password"
}
],
"fallbacks": [
{
"dest": 8080
}
]
},
"streamSettings": {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"minVersion": "1.3",
"certificates": [
{
"certificateFile": "/usr/local/etc/xray/certs/cert.pem",
"keyFile": "/usr/local/etc/xray/certs/key.pem"
}
]
}
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
]
}
客户端配置教程
在 v2rayN(Windows)中使用
v2rayN 是 Windows 平台最推荐的基于 Xray 的 GUI 客户端。
安装 v2rayN:
从 github.com/2dust/v2rayN/releases 下载最新版本的 v2rayN-with-core.zip,解压后运行 v2rayN.exe。
添加 VLESS + Reality 节点:
- 在 v2rayN 界面中,点击"服务器"菜单 → "添加 VLESS 服务器"
- 填写以下信息:
- 地址:服务器 IP
- 端口:443
- 用户 ID:你的 UUID
- 传输协议:tcp
- 伪装类型:none
- 流控(flow):xtls-rprx-vision
- 安全:reality
- 公钥:你的 Public key
- Short ID:你配置的 shortId
- SNI:www.apple.com
- 指纹:chrome
- 点击确认保存,右键节点选择"设为活动服务器"
- 在右下角系统托盘图标右键,选择"自动配置系统代理"
导入订阅(机场用户):
- 点击"订阅分组"菜单 → "订阅分组设置"
- 添加订阅地址(支持 V2Ray / Xray 格式的订阅 URL)
- 点击"更新全部订阅"
切换核心(v2rayN 同时支持 Xray 和 sing-box):
在"设置"→"参数设置"→"Core 类型"中,可以选择使用 Xray 核心或 sing-box 核心处理连接。对于 VLESS + Reality,应选择 Xray 核心。
在 Shadowrocket(iOS)中使用
Shadowrocket 原生支持 VLESS + Reality,配置方式如下:
添加节点:
- 点击右上角 "+" 按钮
- 类型选择 "VLESS"
- 填写以下信息:
- 服务器:服务器 IP
- 端口:443
- UUID:你的 UUID
- TLS:开启
- 传输方式:TCP
- Flow:xtls-rprx-vision
- TLS 安全类型:Reality
- Public Key:你的公钥
- Short ID:你的 shortId
- SNI:www.apple.com
- 指纹(Fingerprint):chrome
- 点击完成保存
通过 URI 导入(更快捷):
VLESS + Reality 节点的 URI 格式如下:
vless://uuid@server_ip:443?security=reality&sni=www.apple.com&fp=chrome&pbk=public_key&sid=short_id&flow=xtls-rprx-vision&type=tcp#节点名称
将上述 URI 复制后,在 Shadowrocket 中点击右上角 "+" → 选择"从剪贴板导入"即可。
在 NekoBox(Android)中使用
NekoBox 基于 sing-box 内核,也支持通过 Xray 格式的 URI 导入节点。
从剪贴板导入:
复制节点的 VLESS URI 后,打开 NekoBox,点击右上角菜单 → "从剪贴板导入"。
手动添加节点:
- 点击右下角 "+" 按钮
- 选择类型为 "VLESS"
- 填写服务器、端口、UUID、流控和 Reality 参数
- 保存后长按节点选择"选择此服务器"
Xray 服务端管理命令
systemd 管理
# 启动服务
systemctl start xray
# 停止服务
systemctl stop xray
# 重启服务
systemctl restart xray
# 重新加载配置(部分更改无需完全重启)
systemctl reload xray
# 查看运行状态
systemctl status xray
# 查看实时日志
journalctl -u xray -f
# 查看最近 100 行日志
journalctl -u xray -n 100
# 开机自启
systemctl enable xray
# 禁止开机自启
systemctl disable xray
验证配置文件
在重启服务之前,建议先验证配置文件语法,避免因配置错误导致服务无法启动:
xray run -test -config /usr/local/etc/xray/config.json
如果配置正确,会输出 Configuration OK;如果有错误,会显示具体的错误位置和原因。
更新 Xray
bash <(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh) install
更新后服务会自动重启。
更新 GeoIP / GeoSite 数据文件
# 从 Loyalsoldier 的 GitHub 仓库下载最新数据文件(包含更多中国域名)
wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat \
-O /usr/local/share/xray/geoip.dat
wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat \
-O /usr/local/share/xray/geosite.dat
# 重启 Xray 使新数据文件生效
systemctl restart xray
建议将更新命令配置为定期执行(如每周一次):
# 编辑 crontab
crontab -e
# 添加每周日凌晨 3 点更新
0 3 * * 0 wget -q https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat -O /usr/local/share/xray/geoip.dat && wget -q https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat -O /usr/local/share/xray/geosite.dat && systemctl restart xray
路由配置详解
Xray 的路由系统通过 routing 字段配置,支持基于多个维度的精细规则。
基础路由配置
{
"routing": {
"domainStrategy": "IPIfNonMatch",
"domainMatcher": "hybrid",
"rules": [
{
"type": "field",
"domain": ["geosite:category-ads-all"],
"outboundTag": "block"
},
{
"type": "field",
"domain": ["geosite:cn"],
"outboundTag": "direct"
},
{
"type": "field",
"ip": ["geoip:cn", "geoip:private"],
"outboundTag": "direct"
},
{
"type": "field",
"network": "tcp,udp",
"outboundTag": "proxy"
}
]
}
}
domainStrategy 说明
| 值 | 说明 |
|---|---|
AsIs | 只按域名匹配规则,不解析 IP,速度最快 |
IPIfNonMatch | 域名规则未命中时,解析 IP 后再次匹配 IP 规则(推荐) |
IPOnDemand | 遇到 IP 规则时立即解析域名,精度最高但延迟略高 |
domainMatcher 说明
| 值 | 说明 |
|---|---|
linear | 线性匹配,兼容性最好 |
hybrid | 混合匹配算法,性能更优,推荐在现代版本中使用 |
规则字段说明
| 字段 | 示例值 | 说明 |
|---|---|---|
domain | ["geosite:cn", "domain:example.com"] | 域名匹配,支持 geosite 引用、完整域名和关键词 |
ip | ["geoip:cn", "192.168.0.0/16"] | IP 匹配,支持 geoip 引用和 CIDR |
port | "80,443,8080-9000" | 目标端口或端口范围 |
network | "tcp" 或 "udp" 或 "tcp,udp" | 传输协议 |
protocol | ["http", "tls", "quic"] | 应用层协议(需开启 sniffing) |
inboundTag | ["socks-in"] | 来自哪个入站 |
outboundTag | "proxy" | 路由到哪个出站 |
balancerTag | "balancer" | 路由到哪个负载均衡器 |
DNS 配置
Xray 内置了完整的 DNS 处理模块,支持防污染的分域名 DNS 查询:
{
"dns": {
"hosts": {
"dns.google": "8.8.8.8",
"dns.pub": "119.29.29.29"
},
"servers": [
{
"address": "https://1.1.1.1/dns-query",
"domains": ["geosite:geolocation-!cn"],
"queryStrategy": "UseIPv4"
},
{
"address": "https://doh.pub/dns-query",
"domains": ["geosite:cn"],
"queryStrategy": "UseIPv4"
},
"localhost"
],
"disableCache": false,
"disableFallback": false,
"queryStrategy": "UseIPv4"
}
}
说明:
hosts:将特定域名强制解析为指定 IP,优先于 DNS 服务器servers中的domains字段:只有符合条件的域名才会向该 DNS 服务器查询queryStrategy:控制是否查询 IPv4 / IPv6,UseIPv4只查询 A 记录,UseIPv6只查询 AAAA 记录,UseIP两者都查
关于 DNS 防污染
Xray 的 DNS 分流策略与 Mihomo 类似:中国域名走国内 DNS(如 doh.pub),境外域名走境外 DNS(如 1.1.1.1),避免 DNS 污染导致境外域名解析到错误 IP。
FakeDNS 配置
Xray 支持 FakeDNS 模式,原理与 Mihomo 的 Fake-IP 相同:
{
"fakedns": [
{
"ipPool": "198.18.0.0/15",
"poolSize": 32768
},
{
"ipPool": "fc00::/18",
"poolSize": 32768
}
],
"dns": {
"servers": [
{
"address": "fakedns",
"domains": ["geosite:geolocation-!cn"]
},
{
"address": "https://doh.pub/dns-query",
"domains": ["geosite:cn"]
}
]
}
}
使用 FakeDNS 时,入站需要开启 sniffing 并在 destOverride 中添加 fakedns:
{
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls", "quic", "fakedns"],
"metadataOnly": false
}
}
多用户配置
Xray 支持在同一入站中配置多个用户:
{
"inbounds": [
{
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "uuid-for-user1",
"flow": "xtls-rprx-vision",
"email": "user1@example.com"
},
{
"id": "uuid-for-user2",
"flow": "xtls-rprx-vision",
"email": "user2@example.com"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {
"dest": "www.apple.com:443",
"serverNames": ["www.apple.com"],
"privateKey": "your-private-key-here",
"shortIds": ["a1b2c3d4", "e5f6g7h8"]
}
}
}
]
}
email 字段用于在流量统计和日志中区分不同用户,建议填写,格式任意(不必须是邮件地址)。
流量统计
启用流量统计可以监控每个用户的入出站流量:
{
"stats": {},
"policy": {
"levels": {
"0": {
"statsUserUplink": true,
"statsUserDownlink": true
}
},
"system": {
"statsInboundUplink": true,
"statsInboundDownlink": true,
"statsOutboundUplink": true,
"statsOutboundDownlink": true
}
},
"api": {
"tag": "api",
"services": ["StatsService"]
},
"inbounds": [
{
"tag": "api",
"port": 10085,
"listen": "127.0.0.1",
"protocol": "dokodemo-door",
"settings": {
"address": "127.0.0.1"
}
}
],
"routing": {
"rules": [
{
"inboundTag": ["api"],
"outboundTag": "api",
"type": "field"
}
]
}
}
查询统计数据:
# 查询所有统计数据
xray api statsquery --server=127.0.0.1:10085
# 查询特定用户的流量
xray api statsquery --server=127.0.0.1:10085 -pattern "user1@example.com"
客户端支持
| 平台 | 客户端 | 支持方式 |
|---|---|---|
| Windows | v2rayN | 原生 Xray-core 集成,功能最完整 |
| macOS | v2rayN(macOS 版)、Homebrew xray | 原生支持 |
| Linux | xray 命令行、v2rayN(Linux 版) | 原生支持 |
| iOS | Shadowrocket | 支持 VLESS + Reality 等所有主流 Xray 协议 |
| iOS | Stash | 通过 Mihomo 核心支持,Reality 支持需较新版本 |
| iOS | Loon、Surge | 支持主要协议 |
| Android | v2rayNG | Xray 内核,支持完整 |
| Android | NekoBox、Husi | 通过 sing-box 内核支持,协议兼容 |
| 路由器 | PassWall / PassWall2 | 在 OpenWrt 上以 Xray 为内核运行 |
常见问题
Q:Xray 和 sing-box 我应该选哪个作为服务端?
两者均可用于服务端部署,主要区别:
- 如果你使用的是 VLESS + Reality,Xray 是原生实现,细节支持更完整,Reality 相关的新特性(如 shortId 列表、更新版本的 uTLS 指纹)优先在 Xray 中实现
- 如果你需要 AnyTLS 或其他 sing-box 原创协议,则必须使用 sing-box 作为服务端
- 两者的配置格式不同(JSON 但字段名有差异),选择后请确保客户端配置与服务端匹配
Q:配置文件改动后,是 reload 还是 restart?
Xray 支持通过 systemctl reload xray(等价于发送 SIGHUP)热重载配置,但并非所有配置项都支持热重载(例如监听端口的变更通常需要完全重启)。为保险起见,修改配置后建议先 xray run -test 验证语法,再执行完整重启。
Q:开启 Reality 后,服务器访问 dest 目标网站会消耗我的流量吗?
是的,每当有新的代理连接建立时,Reality 服务端会向 dest 配置的目标网站(如 www.apple.com)发起一次真实的 TLS 握手,这会消耗服务器的少量出站流量。握手本身数据量很小(通常在 5KB 以内),对于大多数 VPS 的流量套餐而言可以忽略不计。
Q:Reality 的 dest 配置成域名还是 IP?
应当配置为域名(如 www.apple.com:443),而非 IP 地址。使用域名时,TLS 握手中的 SNI 与目标一致,流量特征最为自然。使用裸 IP 会导致 TLS 握手异常,反而暴露特征。
Q:shortIds 配置的作用是什么?
shortIds 是一个字符串列表,客户端在 Reality 握手时会携带其中一个 ID。服务端通过验证收到的 short ID 是否在列表中,来判断连接是否来自合法的 Xray 客户端。这一机制防止普通 TLS 扫描工具冒充合法客户端探测服务端行为。
你可以配置多个 short ID,让不同设备或用户使用不同的 ID,便于区分和管理。
Q:使用 VLESS + Reality,客户端的 fingerprint 应该选什么?
fingerprint 用于模拟特定浏览器的 TLS Client Hello 指纹。推荐选择:
chrome:最常见,模拟 Chrome 浏览器,推荐首选firefox:模拟 Firefox 浏览器safari:模拟 Safari 浏览器(iOS 用户可选)edge:模拟 Edge 浏览器
避免使用 randomized(随机化),因为随机指纹可能产生不符合任何真实浏览器特征的异常指纹,反而更容易被识别。
Q:Xray 支持 Shadowsocks 2022 的多用户模式吗?
支持。在 shadowsocks 入站的 settings 中,可以配置多个用户各自使用独立密钥,配置方式与 sing-box 类似:
{
"protocol": "shadowsocks",
"settings": {
"method": "2022-blake3-aes-256-gcm",
"password": "server-master-key-base64",
"clients": [
{
"password": "user1-key-base64",
"email": "user1"
},
{
"password": "user2-key-base64",
"email": "user2"
}
]
}
}
相关资源
- Xray 官方文档:xtls.github.io
- Xray GitHub:github.com/XTLS/Xray-core
- Xray 安装脚本:github.com/XTLS/Xray-install
- v2ray-rules-dat(Loyalsoldier 增强版规则数据):github.com/Loyalsoldier/v2ray-rules-dat
- v2rayN(Windows GUI):github.com/2dust/v2rayN
- v2rayNG(Android GUI):github.com/2dust/v2rayNG