以下是两套 VLESS 协议配置示例,分别基于:

  1. VLESS + WS + TLS:适用于 Cloudflare/CDN 中转、伪装为网站流量
  2. VLESS + Reality:适用于强封锁环境,无需域名证书,模拟真实 HTTPS 流量(伪装)

分别提供:

  • Sing-box 配置
  • Xray-core 配置

🛡️ 1. VLESS + WS + TLS 示例配置

✅ 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
{
"inbounds": [
{
"type": "vless",
"listen": "::",
"listen_port": 443,
"users": [
{
"uuid": "1e2f3a4b-xxxx-xxxx-xxxx-abcdef123456",
"flow": "xtls-rprx-vision",
"level": 0
}
],
"transport": {
"type": "ws",
"path": "/ray"
},
"tls": {
"enabled": true,
"certificate_path": "/etc/ssl/certs/fullchain.pem",
"key_path": "/etc/ssl/private/privkey.pem"
}
}
],
"outbounds": [
{ "type": "direct" },
{ "type": "block", "tag": "block" }
]
}

更多信息:https://sing-box.sagernet.org/zh/configuration/outbound/vless/

✅ Xray-core 配置(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
{
"inbounds": [
{
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "1e2f3a4b-xxxx-xxxx-xxxx-abcdef123456",
"level": 0,
"flow": ""
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"security": "tls",
"tlsSettings": {
"certificates": [
{
"certificateFile": "/etc/ssl/certs/fullchain.pem",
"keyFile": "/etc/ssl/private/privkey.pem"
}
]
},
"wsSettings": {
"path": "/ray"
}
}
}
],
"outbounds": [{ "protocol": "freedom" }]
}

🧊 2. VLESS + Reality 示例配置

⚠️ 无需证书,但需伪装真实站点(如 www.cloudflare.com 的公钥),推荐配合 sing-boxxray-core 最新版本。

✅ Sing-box 配置

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
{
"inbounds": [
{
"type": "vless",
"listen": "::",
"listen_port": 443,
"users": [
{
"uuid": "1e2f3a4b-xxxx-xxxx-xxxx-abcdef123456"
}
],
"tls": {
"enabled": true,
"reality": {
"enabled": true,
"handshake": {
"server": "www.cloudflare.com",
"server_port": 443
},
"private_key": "YOUR_PRIVATE_KEY",
"short_id": ["d1cf2f84"]
}
}
}
],
"outbounds": [{ "type": "direct" }]
}

✅ 可通过 sing-box generate reality-keypair 生成 private_keypublic_key,再由客户端使用 public_key


✅ Xray-core 配置(Reality)

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
{
"inbounds": [
{
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "1e2f3a4b-xxxx-xxxx-xxxx-abcdef123456",
"flow": "xtls-rprx-vision"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {
"show": false,
"dest": "www.cloudflare.com:443",
"xver": 0,
"serverNames": ["www.cloudflare.com"],
"privateKey": "YOUR_PRIVATE_KEY",
"shortIds": ["d1cf2f84"]
}
}
}
],
"outbounds": [{ "protocol": "freedom" }]
}

🧪 补充说明

参数 含义说明
uuid 用户唯一身份标识,可通过 uuidgen 工具生成
path(WS) 用于伪装路径,例如 /ray,需前端 CDN 配合
privateKey / shortId(Reality) Reality 加密握手配置;需使用工具生成
tls.certificates 适用于 WS+TLS 方式,Reality 不需要域名证书

在 Sing-box 中,配置文件的存储和管理方式取决于你使用的平台(Linux、Windows、macOS、路由器等)和部署方式(手动、systemd、Docker等)。下面是常见平台的默认路径与手动配置方法。


📁 一、配置文件默认位置

平台 配置文件默认路径 说明
Linux(系统服务) /etc/sing-box/config.json 推荐用于 systemd 启动的服务方式
Linux(手动运行) 任意路径,如 ~/singbox/config.json 启动时需通过 -c 指定配置路径
Windows 同目录或 C:\Users\你名\AppData\... 建议放在可执行文件同目录,如 sing-box.exe 所在处
Docker 宿主机挂载路径 /etc/sing-box/config.json 使用 -v 参数映射配置文件
Android(如 SagerNet) App 内部路径,由 App 管理 一般不手动修改,由订阅导入生成

✍️ 二、如何手动配置(Linux 示例)

✅ 步骤 1:创建配置文件目录

1
sudo mkdir -p /etc/sing-box

✅ 步骤 2:创建配置文件

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

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

粘贴你准备好的配置(如 VLESS + WS + TLS 或 Reality),保存退出。

✅ 步骤 3:测试配置是否有效

1
sing-box check -c /etc/sing-box/config.json

无错误即代表语法正确。

✅ 步骤 4:启动 sing-box(临时手动)

1
sing-box run -c /etc/sing-box/config.json

🛠️ 三、建议使用 systemd 启动(持久化服务)

新建服务文件:

1
sudo nano /etc/systemd/system/sing-box.service

内容如下:

1
2
3
4
5
6
7
8
9
10
11
[Unit]
Description=Sing-box Proxy Service
After=network.target

[Service]
ExecStart=/usr/local/bin/sing-box run -c /etc/sing-box/config.json
Restart=on-failure
User=nobody

[Install]
WantedBy=multi-user.target

请根据实际安装路径修改 ExecStart 路径(你安装 sing-box 的位置)

启动并设置开机自启:

1
2
3
4
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable sing-box
sudo systemctl start sing-box

📎 配置调试技巧

操作 命令
测试配置合法性 sing-box check -c config.json
前台运行测试 sing-box run -c config.json
查看运行日志(systemd) journalctl -u sing-box -f
关闭服务 sudo systemctl stop sing-box

📌 提示

  • 配置建议用 JSON 格式(v1 版本)或 YAML(v2,需指定 --config-type yaml)。
  • 推荐使用 Sing-box 官方提供的命令生成密钥:

    1
    sing-box generate reality-keypair
  • 可参考官方文档:https://sing-box.sagernet.org/