Debian & Ubuntu 搭建部署 sing-box 的 NaiveProxy 代理服务

Contents
  1. 1. 背景与原理
    1. 1.1. 整体架构
    2. 1.2. 关于 HTTP/3
    3. 1.3. 本方案不适用的场景
  2. 2. 准备工作
    1. 2.1. 所需资源
    2. 2.2. DNS 配置
    3. 2.3. 创建 Cloudflare API Token
    4. 2.4. 安装基本工具
    5. 2.5. 防火墙放行端口
  3. 3. 安装 sing-box
  4. 4. 服务端配置
    1. 4.1. 生成用户名与密码
    2. 4.2. sing-box 配置
    3. 4.3. 关键字段说明
    4. 4.4. 检查并启动
  5. 5. 验证服务端
  6. 6. 客户端配置
    1. 6.1. 客户端关键字段说明
  7. 7. 隐蔽性评估
  8. 8. 维护与排查
    1. 8.1. 更新 sing-box
    2. 8.2. 查看证书与续签状态
    3. 8.3. 定期轮换密码
    4. 8.4. 常见排查
    5. 8.5. 升级至 sing-box 1.14 后的调整
  9. 9. References

本文最后更新于 2026 年 5 月 14 日


本文以 Debian 13 为例,介绍如何使用 sing-box 搭建 NaiveProxy 兼容服务端,并在客户端使用 sing-box 的 naive outbound 连接。本文同样适用于 Ubuntu 24.04 及以上系统。

本方案有以下特点:

  1. 服务端与客户端均使用 sing-box,无需 Caddy、Nginx、HAProxy 或 Go 编译环境
  2. 使用 sing-box 内置 ACME DNS-01 自动申请和续签真实 TLS 证书,无需开放 TCP 80
  3. 服务端同时监听 TCP 443 与 UDP 443,支持 HTTP/2 与 HTTP/3;客户端默认使用 HTTP/3
  4. 两端均为 sing-box 时可启用 UDP over TCP,兼顾 UDP 应用兼容性
  5. DNS 记录使用 Cloudflare 托管时必须保持 DNS only / 灰云,不要开启橙云代理

注:请先参照 Debian & Ubuntu 服务器的初始化配置 一文对服务器进行各种必要的配置。本文以 sammy 用户为例,并默认已按初始化配置文章对服务器进行了配置。


背景与原理

整体架构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
客户端 sing-box
│ TUN / mixed / socks 入站

sing-box Naive outbound
│ HTTP/3 CONNECT over QUIC / UDP 443
│ SNI: naive.example.com

VPS 公网 IP:443


sing-box Naive inbound
│ 用户名 + 密码认证

direct outbound


目标网站

NaiveProxy 的设计目标是将代理流量伪装成普通浏览器与 Web 服务器之间的 HTTP/2 或 HTTP/3 流量。sing-box 的 naive inbound / outbound 实现了兼容 NaiveProxy 的服务端与客户端。

需要注意:sing-box 的 Naive inbound 是纯代理入口,没有 Caddy forwardproxy 那样的伪装站 fallback。浏览器直接访问 https://naive.example.com 不一定显示正常网页。若强依赖伪装站 fallback,需要另行评估 Caddy forwardproxy 或 HAProxy 方案;本文不使用它们。

关于 HTTP/3

本文默认客户端启用 HTTP/3 / QUIC:

1
"quic": true

HTTP/3 更接近现代 Chrome 访问大量网站时的网络行为,在移动网络、跨国链路或丢包网络下也可能表现更好。但 H3 依赖 UDP 443,如果本地网络或 VPS 商家对 UDP 限速、QoS 或阻断,表现可能不如 H2。遇到连接失败、速度波动或间歇性断流时,删除客户端中的 "quic": true 即可回退到 HTTP/2。

本方案不适用的场景

  1. 必须隐藏 VPS 真实 IP 的场景
  2. 必须通过 Cloudflare Tunnel / CDN 的场景
  3. 必须让浏览器直接访问代理域名显示伪装站的场景
  4. 无法开放公网 TCP 443 与 UDP 443 的 NAT VPS 场景

准备工作

所需资源

  1. 一台 VPS,拥有公网 IPv4,推荐同时有 IPv6
  2. 一个域名,NS 托管到 Cloudflare
  3. 一个 Cloudflare API Token,用于 DNS-01 签发证书
  4. 客户端设备,需使用支持 sing-box Naive outbound 的客户端或官方 sing-box 命令行版本

下文假设域名为 example.com,Naive 服务使用子域名:

1
naive.example.com

请根据实际情况替换。

DNS 配置

在 Cloudflare DNS 中添加记录:

类型名称内容代理状态
AnaiveVPS IPv4 地址DNS only
AAAAnaiveVPS IPv6 地址,可选DNS only

务必确认是灰云 DNS only,不是橙云 Proxied

等待 DNS 生效后,在本地终端检查:

1
2
dig naive.example.com A +short
dig naive.example.com AAAA +short

返回结果应为 VPS 的真实 IP。

创建 Cloudflare API Token

进入 Cloudflare Dashboard → My Profile → API Tokens → Create Token,创建自定义 Token:

项目
PermissionsZone - DNS - Edit
Zone Resources仅选择当前域名

sing-box 的 Cloudflare DNS-01 provider 支持只填写 api_tokenzone_token 是可选项,用于额外提供 Zone:Read 权限;通常不需要。

安装基本工具

1
sudo apt update && sudo apt install curl vim wget ca-certificates openssl -y

防火墙放行端口

本文使用 DNS-01 签发证书,因此不需要开放 TCP 80。只放行 443:

1
2
3
4
sudo ufw allow 443/tcp
sudo ufw allow 443/udp
sudo ufw reload
sudo ufw status verbose

TCP 443 用于 HTTP/2 / HTTPS,UDP 443 用于 HTTP/3 / QUIC。


安装 sing-box

sing-box 官方提供 APT 仓库,推荐优先使用此方式,便于后续升级。

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo mkdir -p /etc/apt/keyrings &&
sudo curl -fsSL https://sing-box.app/gpg.key -o /etc/apt/keyrings/sagernet.asc &&
sudo chmod a+r /etc/apt/keyrings/sagernet.asc &&
echo '
Types: deb
URIs: https://deb.sagernet.org/
Suites: *
Components: *
Enabled: yes
Signed-By: /etc/apt/keyrings/sagernet.asc
' | sudo tee /etc/apt/sources.list.d/sagernet.sources &&
sudo apt-get update &&
sudo apt-get install sing-box

验证版本:

1
sing-box version

截至 2026 年 5 月,建议使用 1.13 系列稳定版。1.14 仍处于 alpha 阶段,配置迁移可等稳定版发布后再处理。


服务端配置

生成用户名与密码

用户名可以使用普通字符串,例如:

1
sammy

密码建议使用随机字符串:

1
openssl rand -base64 24

输出示例:

1
vJ0wP0s8j3QLg2Y+Qd7mP2F9Y9YlDLJ3

下文假设:

1
2
username = sammy
password = vJ0wP0s8j3QLg2Y+Qd7mP2F9Y9YlDLJ3

请替换为自己的值。

sing-box 配置

编辑 /etc/sing-box/config.json

1
sudo vim /etc/sing-box/config.json

写入以下配置,注意替换域名、邮箱、Cloudflare Token、用户名与密码:

/etc/sing-box/config.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{
"log": {
"level": "warn",
"timestamp": true
},
"dns": {
"servers": [
{
"type": "https",
"tag": "cloudflare",
"server": "1.1.1.1"
}
],
"strategy": "prefer_ipv4"
},
"inbounds": [
{
"type": "naive",
"tag": "naive-in",
"listen": "::",
"listen_port": 443,
"users": [
{
"username": "sammy",
"password": "vJ0wP0s8j3QLg2Y+Qd7mP2F9Y9YlDLJ3"
}
],
"quic_congestion_control": "bbr",
"tls": {
"enabled": true,
"server_name": "naive.example.com",
"alpn": [
"h3",
"h2"
],
"acme": {
"domain": [
"naive.example.com"
],
"email": "[email protected]",
"dns01_challenge": {
"provider": "cloudflare",
"api_token": "替换为你的 Cloudflare API Token"
}
}
}
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct",
"domain_resolver": "cloudflare"
}
],
"route": {
"rules": [
{
"action": "sniff"
},
{
"ip_is_private": true,
"action": "reject"
},
{
"protocol": "bittorrent",
"action": "reject"
}
],
"final": "direct"
}
}

限制配置权限:

1
2
sudo chown root:root /etc/sing-box/config.json
sudo chmod 600 /etc/sing-box/config.json

关键字段说明

inbounds[].type:设为 naive,启用 NaiveProxy 兼容服务端。

listen:示例使用 ::,通常可同时监听 IPv6 与 IPv4。若你的系统没有 IPv6,或 ss 检查发现只监听 IPv6,可改为 0.0.0.0

network:本文不写该字段。sing-box 文档说明 network 可为 tcpudp,为空时同时监听 TCP 与 UDP。

quic_congestion_control:设为 bbr。这也是 Chromium / QUICHE 默认使用的 QUIC 拥塞控制。

tls.acme.dns01_challenge:使用 Cloudflare DNS-01 签发证书。配置 DNS-01 后不需要开放 80,也不需要额外运行 acme.sh

tls.alpn:同时提供 h3h2。客户端默认使用 H3,必要时可回退 H2。

检查并启动

1
2
sudo sing-box check -c /etc/sing-box/config.json
sudo systemctl enable --now sing-box

查看状态:

1
2
sudo systemctl status sing-box
sudo journalctl -u sing-box -e --no-pager

首次启动时,sing-box 会通过 Cloudflare DNS-01 申请证书。如果失败,优先检查 DNS 是否为灰云、Token 权限是否为当前域名的 Zone - DNS - Edit、域名与邮箱是否填写正确。


验证服务端

检查监听端口:

1
2
sudo ss -tlnp | grep ':443'
sudo ss -ulnp | grep ':443'

正常情况下,TCP 443 与 UDP 443 都应由 sing-box 监听。

确认 TLS 与 HTTP/2:

1
openssl s_client -connect naive.example.com:443 -servername naive.example.com -alpn h2 -brief

如果能看到证书验证通过,并且 ALPN 协商出 h2,说明 TLS 与 H2 基本正常。H3 是否可用主要看 UDP 443 是否可达,客户端实际连接更有参考价值。

注意:浏览器直接访问 https://naive.example.com 不显示正常网页是预期现象。sing-box naive inbound 没有伪装站 fallback。


客户端配置

sing-box 的 Naive outbound 从 1.13.0 起加入。官方说明中,Naive outbound 只在 Apple platforms、Android、Windows 和部分 Linux 构建中可用。

Linux 客户端如通过 sing-box 官方 APT 仓库安装,通常无需手动处理 Cronet 依赖。只有手动下载官方 release 或使用第三方构建时,才需要确认该构建支持 Naive outbound,并能正确加载 libcronet.so

以下为客户端示例配置,国内网站直连,其他流量走 Naive。两端均为 sing-box,因此默认开启 UDP over TCP v2。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{
"log": {
"level": "warn"
},
"dns": {
"servers": [
{
"type": "https",
"tag": "remote",
"server": "1.1.1.1",
"detour": "proxy"
},
{
"type": "udp",
"tag": "local",
"server": "223.5.5.5"
}
],
"rules": [
{
"rule_set": "geosite-cn",
"server": "local"
}
],
"final": "remote",
"strategy": "prefer_ipv4"
},
"inbounds": [
{
"type": "tun",
"tag": "tun-in",
"address": [
"172.19.0.1/30",
"fdfe:dcba:9876::1/126"
],
"auto_route": true,
"strict_route": true
}
],
"outbounds": [
{
"type": "naive",
"tag": "proxy",
"server": "naive.example.com",
"server_port": 443,
"username": "sammy",
"password": "vJ0wP0s8j3QLg2Y+Qd7mP2F9Y9YlDLJ3",
"insecure_concurrency": 0,
"udp_over_tcp": {
"enabled": true,
"version": 2
},
"quic": true,
"tls": {
"enabled": true,
"server_name": "naive.example.com"
}
},
{
"type": "direct",
"tag": "direct"
}
],
"route": {
"default_domain_resolver": "local",
"rules": [
{
"action": "sniff"
},
{
"protocol": "dns",
"action": "hijack-dns"
},
{
"ip_is_private": true,
"outbound": "direct"
},
{
"rule_set": "geosite-cn",
"outbound": "direct"
},
{
"rule_set": "geoip-cn",
"outbound": "direct"
}
],
"rule_set": [
{
"type": "remote",
"tag": "geosite-cn",
"format": "binary",
"url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-cn.srs",
"download_detour": "proxy"
},
{
"type": "remote",
"tag": "geoip-cn",
"format": "binary",
"url": "https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs",
"download_detour": "proxy"
}
],
"final": "proxy",
"auto_detect_interface": true
},
"experimental": {
"cache_file": {
"enabled": true
}
}
}

客户端关键字段说明

outbounds[].type:设为 naive,表示使用 NaiveProxy outbound。

server:填写域名 naive.example.com。如果需要使用 IP 直连,也可以把这里改成 VPS IP,但 tls.server_name 仍应保持域名。

username / password:必须与服务端 users 中的配置一致。

insecure_concurrency:保持 0。多个并发隧道可能提升吞吐,但会增加流量分析特征,不建议默认开启。

udp_over_tcp:启用 UoT v2,用于承载 UDP 流量。两端都是 sing-box 时建议开启。

quic:设为 true,使用 HTTP/3 / QUIC。若当前网络 UDP 443 不稳定,删除该字段即可回退到 HTTP/2。

tls.server_name:用于证书校验和 TLS SNI。必须与证书域名一致。

Naive outbound 的 TLS 配置不要像 VLESS 那样堆 utlsalpnfingerprint 等字段。Naive outbound 的核心是 Cronet / Chromium 网络栈本身,和普通 sing-box TLS outbound 的配置思路不同。


隐蔽性评估

检测者视角大致如下:

检测维度看到的内容
连接目标 IPVPS 真实 IP
SNInaive.example.com
证书Let’s Encrypt 等公开 CA 签发的真实证书
传输协议HTTP/3 over QUIC,或回退 HTTP/2 over TLS
代理语义HTTP CONNECT
浏览器直接访问不显示伪装站
源站隐藏不隐藏

Naive 仍然存在 TLS-in-TLS 特征,因为用户访问 HTTPS 网站时,内层 HTTPS 流量会被封装在外层 HTTPS CONNECT 隧道中。Naive 的 padding 能缓解部分长度特征,但不能让 TLS-in-TLS 现象完全消失。

简单理解:

目标更适合的方案
隐藏源站 IPVLESS + HTTPUpgrade / WS / gRPC + Cloudflare Tunnel
直连、低延迟、Chrome/Cronet 特征NaiveProxy / sing-box naive
减少 TLS-in-TLS 特征AnyTLS + REALITY 或 VLESS + Vision + REALITY
需要伪装站 fallbackCaddy forwardproxy 或 HAProxy 方案
需要完整 UDP 代理Hysteria2 / TUIC 等方案

维护与排查

更新 sing-box

1
2
3
sudo apt update
sudo apt upgrade sing-box -y
sudo systemctl restart sing-box

查看版本:

1
sing-box version

查看证书与续签状态

sing-box 会自动续签 ACME 证书。可检查最近日志:

1
sudo journalctl -u sing-box --since "7 days ago" --no-pager | grep -i -E 'acme|certificate|renew'

也可以外部检查证书有效期:

1
2
echo | openssl s_client -servername naive.example.com -connect naive.example.com:443 2>/dev/null \
| openssl x509 -noout -dates

定期轮换密码

建议每 3-6 个月轮换一次密码:

1
openssl rand -base64 24

然后同时更新服务端与客户端配置:

1
2
3
sudo vim /etc/sing-box/config.json
sudo sing-box check -c /etc/sing-box/config.json
sudo systemctl restart sing-box

常见排查

  1. ACME 证书签发失败:确认 DNS 记录为灰云,Cloudflare Token 有当前域名的 Zone - DNS - Edit 权限,域名解析已生效。
  2. TCP/H2 可用,H3 不可用:检查 UDP 443 是否放行,VPS 商家和本地网络是否限制 UDP。无法解决时删除客户端 "quic": true 回退 H2。
  3. 客户端提示证书错误:检查 tls.server_name 是否与证书域名一致。
  4. Linux 客户端提示 Naive outbound 不可用:确认使用包含 Cronet 的 sing-box 构建,并且 libcronet.so 能被加载。
  5. 浏览器访问域名不是正常网站:这是 sing-box native naive inbound 的预期现象,不代表代理不可用。
  6. 部分 UDP 应用异常:确认客户端 udp_over_tcp 已启用;若仍不稳定,说明该应用更适合 Hysteria2 / TUIC 等原生 UDP 方案。

升级至 sing-box 1.14 后的调整

本文配置以 sing-box 1.13 稳定版为准。1.14.0 起,TLS 内联 acme 配置迁移为 certificate_providers。等 1.14 稳定版发布并确认兼容后,可按官方 Migration 文档迁移。


References

sing-box

sing-box - Package Manager

sing-box - Naive Inbound

sing-box - Naive Outbound

sing-box - ACME Certificate Provider

sing-box - DNS01 Challenge Fields

sing-box - UDP over TCP

sing-box - Migration

NaiveProxy

Mastodon