sing-box/docs/configuration/service/api.zh.md

110 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
icon: material/new-box
---
!!! question "自 sing-box 1.14.0 起"
# sing-box API
sing-box API 服务是用于观察与控制正在运行的 sing-box 实例的 gRPC 服务器。
它可以由 iOS、macOS 和 Android 上的 [sing-box 图形客户端](/zh/clients/)(通过 Remote Control 功能)或 [sing-box dashboard](https://github.com/SagerNet/sing-box-dashboard) 访问。
服务器同时接受 [gRPC-Web](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-WEB.md) 请求,
包括用于双向流方法的 [@improbable-eng/grpc-web](https://github.com/improbable-eng/grpc-web) WebSocket 传输。
### 结构
```json
{
"type": "api",
... // 监听字段
"secret": "",
"access_control_allow_origin": [],
"access_control_allow_private_network": false,
"dashboard": {
"enabled": true,
"path": "",
"download_url": "",
"http_client": "", // 或 {}
"update_interval": ""
},
"tls": {}
}
```
### 监听字段
参阅 [监听字段](/zh/configuration/shared/listen/)。
### 字段
#### secret
API 密钥。
客户端通过标准的 `authorization: Bearer <secret>` gRPC metadata 头认证。
默认无需认证。
#### access_control_allow_origin
允许的 CORS 来源,默认使用 `*`
#### access_control_allow_private_network
允许从私有网络访问。
#### dashboard
下载并通过 API 监听器在 `/dashboard/` 提供的 Web 仪表板;其他浏览器请求将被重定向到该路径。
!!! info ""
该对象可以替换为布尔值(等同于 `{ "enabled": <bool> }`
或字符串路径(等同于 `{ "enabled": true, "path": "<string>" }`)。
##### enabled
启用仪表板。
##### path
存放仪表板文件的目录。
默认使用工作目录下的 `dashboard`
如果目录为空,将下载仪表板,并在其中存放 `.etag` 文件以跳过未变更的更新。
非空且不含 `.etag` 文件的目录将按原样提供,且不会自动更新。
##### download_url
仪表板压缩包zip的下载 URL。
默认使用 `https://github.com/SagerNet/sing-box-dashboard/archive/refs/heads/gh-pages.zip`
##### http_client
用于下载仪表板的 HTTP 客户端,行为与远程规则集相同。
参阅 [HTTP 客户端字段](/zh/configuration/shared/http-client/)。
留空时使用默认 HTTP 客户端:即由 [`default_http_client`](/zh/configuration/route/#default_http_client)
指定的客户端,或当 `default_http_client` 为空时使用顶级 `http_clients` 的第一项。
!!! failure "隐式默认已在 sing-box 1.14.0 废弃"
`http_clients``default_http_client` 均未配置时,将使用通过默认出站连接的隐式 HTTP 客户端。
该隐式默认已在 sing-box 1.14.0 废弃,并将在 sing-box 1.16.0 移除;请改为定义 `http_clients`
##### update_interval
仪表板的更新间隔。
默认使用 `1d`
#### tls
TLS 配置,参阅 [TLS](/zh/configuration/shared/tls/#inbound)。