Skip to content

sing-box — 配置结构

sing-box 启动时读取单个 JSON 文档。根对象映射到 option/options.go:12 中的 Go 结构体 _Options(通过类型别名导出为 Options,其 UnmarshalJSONContext 启用了严格的未知字段检查 —— 配置中的拼写错误会 直接导致启动失败,而不是被静默忽略)。

根字段

Go 字段类型页面描述
$schemaSchemastring(无)JSON-schema URL;运行时忽略。
logLog*LogOptions日志严重级别、输出、时间戳、禁用开关。
dnsDNS*DNSOptionsDNSDNS 服务器、规则、hosts、fakeip。
ntpNTP*NTPOptionsNTP可选的内嵌 NTP 客户端。
certificateCertificate*CertificateOptions证书TLS 校验使用的根 CA 来源。
endpointsEndpoints[]Endpoint端点端点形式的入站 / 出站(WireGuard、Tailscale)。
inboundsInbounds[]Inbound入站监听服务列表。
outboundsOutbounds[]Outbound出站上游目标列表。
routeRoute*RouteOptions路由路由规则、rule-set、默认出站。
servicesServices[]Service服务后台服务(resolved、derp、ssm-api)。
experimentalExperimental*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)

由 Argsment 出品的 Core Tutorial