本文发布于 632 天前,部分信息可能随时间变化。
准备工作
- 解析域名Cloudflare:【点击进入】
- 下载SSH连接工具Finalshell:【点击进入】
1、Sing-box开源项目:【点击进入】
- 安装文档:【点击进入】
2、一键安装脚本
bash <(curl -fsSL https://sing-box.app/deb-install.sh)
3、一键申请SSL证书(注意:其他云平台,需要在控制台去设置规则放行所有端口)
sudo apt install git -y && git clone https://github.com/slobys/SSL-Renewal.git /tmp/acme && mv /tmp/acme/* /root && bash acme_2.0.sh
4、移动证书文件到对应目录并重命名
mv /root/你的域名.crt /etc/sing-box/cert.pem
mv /root/你的域名.key /etc/sing-box/key.pem
5、玩法配置/etc/sing-box,打开config.json文件
- 同一入站不同出站
{
"log": {
"level": "info"
},
"dns": {
"servers": [
{
"address": "tls://8.8.8.8",
"detour": "direct"
}
]
},
"inbounds": [
{
"type": "vmess",
"tag": "vmess-in",
"listen": "0.0.0.0",
"listen_port": 20001, //可以自定义端口
"users": [
{
"uuid": "632e9ca9-7b6b-4a61-b91a-7437876938d6", //可以自定义UUID
"alterId": 0
}
],
"transport": {
"type": "ws",
"path": "/demo123" //可以自定义路径
},
"tls": {
"enabled": true,
"certificate_path": "/etc/sing-box/cert.pem",
"key_path": "/etc/sing-box/key.pem"
}
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
},
{
"type": "selector",
"tag": "relay-out",
"default": "node1",
"outbounds": [
"node1",
"node2"
]
},
{
"type": "vmess",
"tag": "node1",
"server": "节点1的域名",
"server_port": 42546,
"uuid": "006fa148-9df6-4e78-a4d1-5379c6f2cb0e",
"security": "auto",
"transport": {
"type": "ws",
"path": "/demo002"
},
"tls": {
"enabled": true
}
},
{
"type": "vmess",
"tag": "node2",
"server": "节点2的域名",
"server_port": 38969,
"uuid": "027e6840-d24e-4bca-a692-ec6bfebfdea1",
"security": "auto",
"transport": {
"type": "ws",
"path": "/demo001"
},
"tls": {
"enabled": true
}
}
],
"route": {
"rules": [
{
"protocol": "dns",
"outbound": "direct"
},
{
"inbound": "vmess-in",
"outbound": "relay-out"
}
]
}
}
- 不同入站对应不同出站
{
"log": {
"level": "info"
},
"dns": {
"servers": [
{
"address": "tls://8.8.8.8",
"detour": "direct"
}
]
},
"inbounds": [
{
"type": "vmess",
"tag": "A1-in",
"listen": "0.0.0.0",
"listen_port": 20001, //可以自定义端口
"users": [
{
"uuid": "632e9ca9-7b6b-4a61-b91a-7437876938d6", //可以自定义UUID
"alterId": 0
}
],
"transport": {
"type": "ws",
"path": "/demo123" //可以自定义路径
},
"tls": {
"enabled": true,
"certificate_path": "/etc/sing-box/cert.pem",
"key_path": "/etc/sing-box/key.pem"
}
},
{
"type": "vmess",
"tag": "A2-in",
"listen": "0.0.0.0",
"listen_port": 20002,
"users": [
{
"uuid": "f6936657-fb73-4aeb-aaea-a1212536b6fd",
"alterId": 0
}
],
"transport": {
"type": "ws",
"path": "/demo456"
},
"tls": {
"enabled": true,
"certificate_path": "/etc/sing-box/cert.pem",
"key_path": "/etc/sing-box/key.pem"
}
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
},
{
"type": "vmess",
"tag": "node1",
"server": "节点1的域名",
"server_port": 42546,
"uuid": "006fa148-9df6-4e78-a4d1-5379c6f2cb0e",
"security": "auto",
"transport": {
"type": "ws",
"path": "/demo002"
},
"tls": {
"enabled": true
}
},
{
"type": "vmess",
"tag": "node2",
"server": "节点2的域名",
"server_port": 38969,
"uuid": "027e6840-d24e-4bca-a692-ec6bfebfdea1",
"security": "auto",
"transport": {
"type": "ws",
"path": "/demo001"
},
"tls": {
"enabled": true
}
}
],
"route": {
"rules": [
{
"inbound": "dns",
"outbound": "direct"
},
{
"inbound": "A1-in",
"outbound": "node1"
},
{
"inbound": "A2-in",
"outbound": "node2"
}
]
}
}
6、服务管理
启用 sudo systemctl enable sing-box
禁用 sudo systemctl disable sing-box
启动 sudo systemctl start sing-box
停止 sudo systemctl stop sing-box
强行停止 sudo systemctl kill sing-box
重新启动 sudo systemctl restart sing-box
查看日志 sudo journalctl -u sing-box --output cat -e
实时日志 sudo journalctl -u sing-box --output cat -f










