Skip to content

实验性

experimental 块承载四块松散相关的功能:持久化缓存文件、与 Clash 兼容的 RESTful API、V2Ray gRPC 统计 API,以及内嵌 pprof / 运行时 调试端点。

字段类型默认值允许值描述
cache_file*CacheFileOptions(unset)CacheFileOptions持久化状态缓存。
clash_api*ClashAPIOptions(unset)ClashAPIOptions与 Clash 面板兼容的外部控制器。
v2ray_api*V2RayAPIOptions(unset)V2RayAPIOptions与 V2Ray 客户端兼容的 gRPC 统计服务。
debug*DebugOptions(unset)DebugOptions内嵌 pprof 端点与 GC 调优。

源码: option/experimental.go:5-10 · 锚定版本 v1.13.11 (553cfa1)

cache_file

持久化磁盘缓存,用于 fakeip 租约、选中代理记忆、RDRC 条目及其他 运行时状态。

字段类型默认值允许值描述
enabledboolfalsetrue | false启用缓存文件。
pathstringcache.db<file path>缓存数据库的存储位置。
cache_idstring(unset)<string>同一缓存文件内的命名空间前缀。多个 sing-box 实例共享一个缓存文件时有用。
store_fakeipboolfalsetrue | false持久化 fakeip 租约表。
store_rdrcboolfalsetrue | false持久化 Reject-DNS-Resolution Cache(rdrc)条目。
rdrc_timeoutbadoption.Duration7d<duration>rdrc 条目在缓存中保留的有效期。

源码: option/experimental.go:12-19 · 锚定版本 v1.13.11 (553cfa1)

clash_api

Clash RESTful API 的内置实现,可与 metacubexd、Yacd、Clash Dashboard 等 Clash API 消费者直接对接。

字段类型默认值允许值描述
external_controllerstring(unset)<host:port>RESTful API 监听地址。
external_uistring(unset)<dir path>用作面板的本地目录。
external_ui_download_urlstringhttps://github.com/MetaCubeX/metacubexd/archive/refs/heads/gh-pages.zip<URL>external_ui 为空时自动下载的 tarball URL。
external_ui_download_detourstring(direct)<outbound tag>下载使用的出站。
secretstring(unset)<bearer token>所有 API 调用所需的 Bearer 令牌,强烈建议设置。
default_modestringrulerule | global | direct | <custom>通过 API 报告的初始隧道模式。也接受自定义值,但非标准面板会忽略它们。
access_control_allow_originbadoption.Listable[string][]<origin>API 的 CORS 允许列表。
access_control_allow_private_networkboolfalsetrue | false允许来自私有网络的 preflight 请求。

源码: option/experimental.go:21-42 · 锚定版本 v1.13.11 (553cfa1)

另有五个字段(cache_filecache_idstore_modestore_selectedstore_fakeip)已弃用,会向前合并进 cache_file 块 —— 新配置中请勿使用。

v2ray_api

V2Ray 兼容的 gRPC 统计 API。若你已有 v2ray api stats query ... 这类工具且希望继续沿用,可以保留它。

字段类型默认值允许值描述
listenstring(required)<host:port>StatsService 的 gRPC 监听地址。
stats*V2RayStatsServiceOptions(unset)V2RayStatsServiceOptions需要统计的对象。

源码: option/experimental.go:44-47 · 锚定版本 v1.13.11 (553cfa1)

v2ray_api.stats

字段类型默认值允许值描述
enabledboolfalsetrue | false启用统计服务。
inbounds[]string[]<inbound tag>需要统计流量的入站 tag。
outbounds[]string[]<outbound tag>需要统计流量的出站 tag。
users[]string[]<user name>按用户的计数器。

源码: option/experimental.go:49-54 · 锚定版本 v1.13.11 (553cfa1)

debug

Go 运行时调优块。多数字段直接对应 runtime / runtime/debug 包 的旋钮。listen 字段暴露标准 net/http/pprof handlers。

字段类型默认值允许值描述
listenstring(unset)<host:port>pprof 端点的监听地址(如 127.0.0.1:6060)。
gc_percent*int(Go default)<int> | -1GOGC 覆盖。-1 禁用 GC。
max_stack*int(Go default)<bytes>单 goroutine 栈上限。
max_threads*int(Go default)<int>GOMAXPROCS 风格的线程上限。
panic_on_fault*boolfalsetrue | false将不可恢复的运行时 fault 转为带栈跟踪的 panic。
trace_backstring(Go default)none | single | all | system | crashGOTRACEBACK 设置。
memory_limit*byteformats.MemoryBytes(unset)<bytes/MiB/GiB>软内存上限;接受纯数字(字节)或带后缀的 256MiB 等。
oom_killer*boolfalsetrue | false持续超出 memory_limit 时让进程崩溃退出。

源码: option/debug.go:5-14 · 锚定版本 v1.13.11 (553cfa1)

示例

json
{
  "experimental": {
    "cache_file": {
      "enabled": true,
      "path": "cache.db",
      "store_fakeip": true
    },
    "clash_api": {
      "external_controller": "127.0.0.1:9090",
      "secret": "<random>",
      "external_ui": "/etc/sing-box/ui"
    },
    "debug": {
      "listen": "127.0.0.1:6060",
      "memory_limit": "256MiB"
    }
  }
}

说明

  • clash_api 上已弃用的缓存相关字段(cache_filecache_idstore_modestore_selectedstore_fakeip)仍可解析,但加载 时会打印警告,未来版本会移除。五者都向前合并进 cache_file 块。
  • debug.memory_limit 接受纯数字(字节)或 "256MiB" / "2GiB" 之类带后缀的字面量,由 byteformats.MemoryBytes 解析。

源码: option/experimental.go:5-54 · v1.13.11 (553cfa1)

由 Argsment 出品的 Core Tutorial