sing‑box 部署教程
概述
sing‑box 一体化代理工具,支持服务端、客户端,多协议,TOML配置格式;常搭配frp内网穿透场景使用。
1. 安装(Linux CentOS)
方式1:官方脚本安装
bash <(curl -Ls https://sing-box.sagernet.org/install.sh)安装完成后systemd服务:sing-box
systemctl enable sing-box
systemctl start sing-box
systemctl restart sing-box
journalctl -u sing-box -f目录
- 主配置文件:
/etc/sing-box/config.json/config.toml - 日志:
/var/log/sing-box/
2. 服务端简单示例(TOML)
注意:公网端口注意云安全组、firewalld放行
[log]
level = "info"
output = "stdout"
[inbounds]
[[inbounds]]
type = "vless"
listen = "0.0.0.0"
port = 20000
uuid = "你的uuid字符串"
flow = "xtls-rprx-vision"
[outbounds]
[[outbounds]]
type = "direct"3. 客户端简单示例(TOML)
[log]
level = "info"
[inbounds]
[[inbounds]]
type = "socks"
listen = "127.0.0.1"
port = 1080
[[inbounds]]
type = "http"
listen = "127.0.0.1"
port = 1081
[outbounds]
[[outbounds]]
type = "vless"
server = "你的服务端IP"
server_port = 20000
uuid = "你的uuid字符串"
flow = "xtls-rprx-vision"
tls.enabled = true4. 与frp联动场景
场景:sing‑box服务端部署在内网机器,通过frp暴露到公网
- sing‑box inbound监听
127.0.0.1:端口; - frpc增加type=tcp代理,remotePort设置对外端口;
- frps服务端安全组放行remotePort;
⚠️tcp代理需要frpc配置remotePort,http代理不能写remotePort。5. 证书说明
- sing‑box内置acme可以自动申请Let’s Encrypt证书;
- 也可以复用Nginx已经申请好的fullchain.pem、privkey.pem;
- 若前置Cloudflare,可使用CF Flexible模式,sing‑box本身不处理证书。
6. 调试命令
# 校验配置文件
sing-box check -c /etc/sing-box/config.toml
# 前台运行测试
sing-box run -c /etc/sing-box/config.toml7. 安全要点
- 公网端口务必限制安全组,最小权限放行;
- 不要直接把管理/调试端口暴露公网;
- 使用强uuid、密钥,避免弱配置;
- 尽量监听127.0.0.1,通过frp/Nginx反向代理对外提供服务。
8. 常见坑
- 配置文件语法错误直接启动失败;优先
sing-box check校验; - 端口冲突:确认端口没有被nginx/frps占用;
- 云服务器安全组与firewalld两层都要放行端口,缺一不可;
- 监听地址写成127.0.0.1会导致外部无法访问。