sing-box — 配置结构
sing-box 启动时读取单个 JSON 文档。根对象映射到 option/options.go:12 中的 Go 结构体 _Options(通过类型别名导出为 Options,其 UnmarshalJSONContext 启用了严格的未知字段检查 —— 配置中的拼写错误会 直接导致启动失败,而不是被静默忽略)。
根字段
| 键 | Go 字段 | 类型 | 页面 | 描述 |
|---|---|---|---|---|
$schema | Schema | string | (无) | JSON-schema URL;运行时忽略。 |
log | Log | *LogOptions | 日志 | 严重级别、输出、时间戳、禁用开关。 |
dns | DNS | *DNSOptions | DNS | DNS 服务器、规则、hosts、fakeip。 |
ntp | NTP | *NTPOptions | NTP | 可选的内嵌 NTP 客户端。 |
certificate | Certificate | *CertificateOptions | 证书 | TLS 校验使用的根 CA 来源。 |
endpoints | Endpoints | []Endpoint | 端点 | 端点形式的入站 / 出站(WireGuard、Tailscale)。 |
inbounds | Inbounds | []Inbound | 入站 | 监听服务列表。 |
outbounds | Outbounds | []Outbound | 出站 | 上游目标列表。 |
route | Route | *RouteOptions | 路由 | 路由规则、rule-set、默认出站。 |
services | Services | []Service | 服务 | 后台服务(resolved、derp、ssm-api)。 |
experimental | Experimental | *ExperimentalOptions | 实验性 | 缓存文件、Clash API、V2Ray API、pprof 调试。 |
一览
json
{
"log": { "level": "info", "timestamp": true },
"dns": { "servers": [{ "tag": "google", "address": "tls://8.8.8.8" }] },
"ntp": { "enabled": true, "server": "time.cloudflare.com" },
"certificate": { "store": "system" },
"inbounds": [],
"outbounds": [],
"route": { "final": "direct" },
"experimental": {
"cache_file": { "enabled": true },
"clash_api": { "external_controller": "127.0.0.1:9090" }
}
}源码: option/options.go:12-25 · v1.13.11 (553cfa1)
