本文档记录在 Windows 上部署 Xray-core 裸核的流程。
资源文件
- 前往 https://github.com/XTLS/Xray-core/releases 下载
Xray-windows-64.zip(推荐 Pre-release,本文以 v26.9.9 为例) - 前往 https://github.com/SagerNet/sing-box/releases 下载
sing-box-1.14.0-windows-amd64.zip(singbox变动频繁,暂时推荐 Release,本文以 v1.14.0 为例)注:如果不打算使用 TUN 虚拟网卡或者打算使用 XrayTUN,可以略过 Singbox 的资源下载
- 前往 https://github.com/winsw/winsw/releases 下载
WinSW-x64.exe(推荐 Pre-release)注:由于 winsw 最近一次的 release 在三年前,更建议克隆仓库自行构建新版本
.NET 10 构建命令为:
Terminal window $HASH = (git rev-parse --short HEAD)dotnet publish src/WinSW/WinSW.csproj -c Release -f net10.0-windows -r win-x64 --self-contained true -p:Version="3.0.0" -p:InformationalVersion="3.0.0-alpha.11+$HASH"- 产物路径:
artifacts\bin\WinSW\Release\net10.0-windows\win-x64\publish\WinSW.exe
- 产物路径:
目录结构
下载完资源文件后,创建如下目录结构:
D:\Programs\Proxy\├── Xray\ # Xray-core 目录│ ├── xray.exe # Xray-core 二进制文件│ ├── wintun.dll # TUN 驱动库(官方资源包附带)│ ├── config\│ │ └── xray.yaml # 你的 Xray 配置文件│ ├── geo\ # 规则库资产目录(官方资源包附带)│ │ ├── geoip.dat│ │ └── geosite.dat│ ├── logs\ # 日志目录│ └── scripts\│ ├── winsw.exe # WinSW 服务包装器│ └── winsw.xml # WinSW 服务文件(自行创建)│└── SingBox\ # Sing-Box 目录 ├── sing-box.exe # Sing-Box 二进制文件 ├── libcronet.dll # Cronet 网络库(官方资源包附带) ├── config\ │ └── sing-box.json # 你的 Sing-Box 配置文件(自行创建) ├── dashboard\ # Web Dashboard 面板资源(可选) ├── logs\ # 日志目录 └── scripts\ ├── winsw.exe # WinSW 服务包装器 └── winsw.xml # WinSW 服务文件(自行创建)配置文件
接下来书写配置文件,需要准备:
xray config
裸核需要 Full Config,请参考我另一篇文章个人 Xray-core 客户端自用配置分享,此处不赘述
singbox config
个人认为,个人认为,个人认为!目前 xray tun 还不够成熟,因此使用 singbox 中的 singtun 代替 xray tun
{ "log": { "level": "warn", "output": "d:\\Programs\\Proxy\\SingBox\\logs\\sing-box.log", "timestamp": true }, "dns": { "servers": [ { "type": "tcp", "tag": "remote-dns", "detour": "to-xray", "server": "8.8.8.8", "server_port": 53 }, { "type": "udp", "tag": "direct-dns", "detour": "direct", "server": "223.5.5.5", "server_port": 53 } ], "final": "remote-dns", "strategy": "prefer_ipv4", "cache_capacity": 4096 }, "inbounds": [ { "type": "tun", "tag": "tun-in", "interface_name": "singbox-tun", "mtu": 9000, "address": [ "172.19.0.1/30", "fdfe:dcba:9876::1/126" ], "auto_route": true, "stack": "system", "endpoint_independent_nat": true } ], "outbounds": [ { "type": "socks", "tag": "to-xray", "server": "127.0.0.1", "server_port": 10808 }, { "type": "direct", "tag": "direct", "domain_resolver": "direct-dns" } ], "route": { "rules": [ { "action": "sniff" }, { "network": "udp", "port": [135, 137, 138, 139, 1900, 3702, 5353], "action": "reject", "method": "drop" }, { "ip_cidr": [ "224.0.0.0/3", "ff00::/8" ], "action": "reject", "method": "drop" }, { "ip_cidr": [ "172.19.0.1/32", "fdfe:dcba:9876::1/128" ], "action": "reject", "method": "drop" }, { "protocol": "dns", "action": "hijack-dns" }, { "process_name": [ "xray.exe", "xray", "Weixin.exe", "QQ.exe", "QQMusic.exe" ], "outbound": "direct" } ], "final": "to-xray", "auto_detect_interface": true }, "experimental": { "cache_file": { "enabled": true }, "clash_api": { "external_controller": "127.0.0.1:9090", "external_ui": "dashboard", "external_ui_download_url": "https://github.com/Zephyruso/zashboard/releases/download/v3.22.0/dist-no-fonts.zip", "external_ui_download_detour": "to-xray", "secret": "SakiSakiSakiSakiSakiSakiSakiSaki", "default_mode": "rule" } }}clash_api 可以使用 Zashboard WebUI 来查看,推荐先把 WebUI 资源包 下载并解压,解压后的目录大致为:
└── SingBox\ # Sing-Box 目录 └── dashboard\ # Zashboard WebUI 面板资源 ├── index.html ├── assets\ # Zashboard 编译产物 │ └── ... └── ...不需要 WebUI 的话,将 "experimental": {……} 删除即可
点击展开/收起 仅推荐 v3.22.0 的原因
zashboard 在 v3.23.0 后不再支持 Sing-box
结束对 sing-box 的支持zashboard 将在3.23.0版本移除对 sing-box 的支持,包括 sing-box 原生 gRPC API 以及 sing-box 提供的 Clash API的兼容性支持。
为什么停止支持
本来只是工作之余出于兴趣写个面板,没想到还有赛博皇帝在那狗叫,没兴趣兼容这种项目了。
使用zashboard的sing-box用户:很抱歉,推荐你们使用其他项目。
xray 目录的 winsw.xml
接下来将xray和singbox封装为系统服务,需要分别为它们创建 winsw.xml
<service> <!-- 服务基本信息 --> <id>Xray</id> <name>Xray Core Service</name> <description>Xray Core Service</description>
<!-- 使用环境变量指定 geo 资产目录 (指向 D:\Programs\Proxy\Xray\geo) --> <env name="xray.location.asset" value="%BASE%\..\geo" />
<!-- 可执行文件指向 D:\Programs\Proxy\Xray\xray.exe --> <executable>%BASE%\..\xray.exe</executable>
<!-- Xray 启动参数 --> <arguments>run -c config\xray.yaml</arguments>
<!-- 工作目录设置为根目录 D:\Programs\Proxy\Xray --> <workingdirectory>%BASE%\..</workingdirectory>
<!-- 启动设置 --> <!-- 设置服务进程的 CPU 优先级 --> <!-- delayedAutoStart: 延迟启动,系统启动完关键服务后再启动此服务 --> <!-- priority: 进程优先级,设置为低于正常优先级,避免影响系统性能 --> <!-- idle:空闲优先级(最低) --> <!-- belownormal:低于正常优先级 --> <!-- normal:正常优先级(默认) --> <!-- abovenormal:高于正常优先级 --> <!-- high:高优先级 --> <!-- realtime:实时优先级(最高,慎用) --> <delayedAutoStart>true</delayedAutoStart> <priority>normal</priority>
<!-- WinSW 自身日志输出 --> <logpath>%BASE%\..\logs</logpath> <log mode="roll-by-size"> <sizeThreshold>2048</sizeThreshold> <keepFiles>14</keepFiles> </log>
<!-- 错误重启与超时设置 --> <onfailure action="restart" delay="10 sec"/> <onfailure action="restart" delay="30 sec"/> <onfailure action="restart" delay="1 min"/>
<resetfailure>1 hour</resetfailure> <stoptimeout>30sec</stoptimeout></service>sing-box 目录的 winsw.xml
同理,创建:
<service> <id>SingBox-Tun</id> <name>SingBox TUN Service</name> <description>SingBox Wintun Layer for Xray</description>
<!-- 使用依赖项让 Xray 先运行,再启动 sing-box TUN --> <depend>Xray</depend>
<executable>%BASE%\..\sing-box.exe</executable> <arguments>run -c config\sing-box.json</arguments> <workingdirectory>%BASE%\..</workingdirectory>
<delayedAutoStart>true</delayedAutoStart> <priority>normal</priority>
<logpath>%BASE%\..\logs</logpath> <log mode="roll-by-size"> <sizeThreshold>2048</sizeThreshold> <keepFiles>7</keepFiles> </log>
<onfailure action="restart" delay="5 sec"/> <onfailure action="restart" delay="15 sec"/> <onfailure action="restart" delay="30 sec"/> <resetfailure>1 hour</resetfailure> <stoptimeout>15sec</stoptimeout></service>安装并启动服务
现在使用 WinSW 安装为服务,以管理员身份启动 pwsh 分别执行:
# 安装 SingTUN 服务d:\Programs\Proxy\SingBox\scripts\winsw.exe install
# 安装 Xray-core 服务d:\Programs\Proxy\Xray\scripts\winsw.exe install安装完成后,请再次检查所需文件是否已准备完毕。
接下来继续在 pwsh 终端执行:
# 由于已经在 winsw.xml 写了 <depend>,只需要启动 singtun 的服务就会自动拉起 xray-cored:\Programs\Proxy\SingBox\scripts\winsw.exe start
# 查看状态,期望输出应是 Active (running)d:\Programs\Proxy\SingBox\scripts\winsw.exe statusd:\Programs\Proxy\Xray\scripts\winsw.exe status教程到这里结束了,下文是可选的配置
可选增强
快捷启停
WinSW 提供了几个执行命令,可以封装为快捷方式,配合 Win10 的开始菜单磁贴使用(Win11 我不知道还能不能用,但放到桌面用也是差不多的)
点击展开/收起 命令详情
.\winsw.exe install # 安装服务.\winsw.exe start # 启动服务.\winsw.exe stop # 停止服务.\winsw.exe restart # 重启服务.\winsw.exe status # 查看状态.\winsw.exe uninstall # 卸载服务创建以下文件:
D:\Programs\Proxy\└── Xray\ ├── xray.exe └── scripts\ ├── winsw.exe ├── winsw.xml ├── restart-xray.ps1 # 重启 ├── start-xray.ps1 # 启动 └── stop-xray.ps1 # 停止点击展开/收起 三个文件写入内容
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.DefinitionSet-Location $scriptDirWrite-Host "Restarting Xray & SingBox-Tun services..."Start-Process winsw.exe -ArgumentList "restart", "--force" -WaitWrite-Host "Xray service restart command issued."$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.DefinitionSet-Location $scriptDirWrite-Host "Starting SingBox-Tun & Xray..."$singboxWinsw = Join-Path $scriptDir "..\..\SingBox\scripts\winsw.exe"Start-Process $singboxWinsw -ArgumentList "start" -WaitWrite-Host "All services started."$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.DefinitionSet-Location $scriptDirWrite-Host "Stopping Xray & SingBox-Tun services..."Start-Process winsw.exe -ArgumentList "stop", "--force" -WaitWrite-Host "Xray service stop command issued."接下来选中这三个脚本,鼠标右键 -> 创建快捷方式

在 C:\Users\你地鸣至\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\ 新建一个文件夹 Proxy,
然后把这三个快捷方式放进去,就能在开始菜单放置磁贴并一键操作了(快捷方式可以自定义图标、名称)

日志轮转
Xray-core 和 Singbox 自身不提供按大小或时间自动切割日志的能力,建议通过外部脚本轮转,或者不写入 log 物理文件
另,Xray-core 提供了 xray api restartlogger,能让 Xray 重新打开日志句柄
这部分不做示例,因为我的脚本写得太乱,你可以让 GenAI 帮助你快速创建一个轮转的 python 脚本
需要轮转的对象:sing-box.log、access.log、error.log
