
什么是 Xray ?
简单粗暴来说,Xray 是用来魔法上网的。
它与大名鼎鼎的 V2ray 有什么区别呢?
介绍个故事。一个 Debian 包维护者发现 XTLS库 的 LICENSE 不是 BSD 许可,提了一个 issue 希望作者 @rprx 能修改方便打包,详见点击 这里。由这个 issue 引发了广泛讨论,rprx 认为目前许可不是问题,也有不少人认为协议是立场的体现,各执一词。
最终 V2ray (V2fly 社区) 维护者经过投票确认 XTLS 不符合 V2ray 的 MIT 协议,并在 V2ray-core 4.33.0版本移除了XTLS。rprx 和其拥护者行动起来,很快就创建了 Project X项目 和 Xray子项目(Xray 取名来自 XTLS和 V2ray 的结合),并发布了 Xray-core 的多个版本,这便是 Xray 的大致由来。
为什么使用 Xray ?
Xray 项目创建以来,V2ray 没再发布新版本,反而 Xray 热火朝天,不断出新版和新功能。
Xray + XTLS 组合号称是黑科技,在性能不佳的小鸡身上,有着明显的速度提升。【我也是听说的,没测过】
喜欢折腾。
安装 Xray 服务
实验环境如下
操作系统 | CentOS 7.9 |
服务器位置 | Dallas, Texas, U.S |
公网 IP | 192.227.193.111 |
通过 官方脚本 安装,首次安装,需要安装 Xray-core 和 geodata。打开 Xshell,使用 root 用户登陆服务器,执行以下命令。
# bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install -u root
配置文件
官方脚本安装的配置文件(路径:/usr/local/etc/xray/config.json)内容为空,可参考 Xray-examples 中提供的模板编辑配置文件。例如使用 VLESS+TCP+XTLS 的配置文件为:
{ "inbounds": [{ "port": 443, "protocol": "vless", "settings": { "clients": [ { "id": "28b01209-da52-48e1-ba69-23b6b156046e", "flow": "xtls-rprx-direct", "level": 0 } ], "decryption": "none", "fallbacks": [ { "alpn": "http/1.1", "dest": 80 }, { "alpn": "h2", "dest": 81 } ] }, "streamSettings": { "network": "tcp", "security": "xtls", "xtlsSettings": { "serverName": "xray.domain.com", "alpn": ["http/1.1", "h2"], "certificates": [ { "certificateFile": "/usr/local/etc/xray/xray.domain.com.pem", "keyFile": "/usr/local/etc/xray/xray.domain.com.key" } ] } } }], "outbounds": [{ "protocol": "freedom", "settings": {} },{ "protocol": "blackhole", "settings": {}, "tag": "blocked" }] }
上述配置文件中,certificateFile 和 keyFile 涉及到 https 域名证书注册问题,点击 这里 参考教程。
守护进程脚本
vim /etc/systemd/system/xray.service
[Unit] Description=Xray Service Documentation=https://github.com/xtls After=network.target nss-lookup.target [Service] User=root #User=nobody #CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE #AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE NoNewPrivileges=true ExecStart=/usr/local/bin/xray run -config /usr/local/etc/xray/config.json Restart=on-failure RestartPreventExitStatus=23 [Install] WantedBy=multi-user.target
重载 Xray 服务并将其加入开机自启
systemctl daemon-reload && systemctl enable xray
启动 Xray 服务
systemctl start xray
客户端配置
服务端配置好后,接下来是配置客户端。目前有如下客户端支持Xray:
v2rayN – 适用于 Windows 平台
请从它的 GitHub 仓库 Release 页面open in new window 获取最新版
请根据该客户端的说明进行设置
v2rayNG – 适用于 Android 平台
请从它的 GitHub 仓库 Release 页面open in new window 获取最新版
请根据该客户端的说明进行设置
Shadowrocket – 适用于 iOS, 基于苹果 M 芯片的 macOS
你需要注册一个【非中国区】的 iCloud 账户
你需要通过 App Store 搜索并购买
请根据该客户端的说明进行设置
V2RayXS – 基于 V2RayX 开发的一款使用 xray-core 的 macOS 客户端
请从它的 GitHub 仓库 Release 页面open in new window 获取最新版
支持一键导入 VMessAEAD / VLESS 分享链接标准提案open in new window 为标准的分享链接
请根据该客户端的说明进行设置