辅助配置文件

Last Updated: 2026-11-30 14:51 Views: 5

所有配置均为 TOML,统一使用 JSON 风格(key = { ... } 多行内联表 + 尾逗号,见 docs/configuration.md 的「输出格式」)。除主配置/vhost/*.toml/cert.toml/acme.toml 外, 以下辅助文件也可通过 Manager → Settings → Raw config 直接编辑; 保存会走 PUT /api/config/raw?file=<path> 并触发热加载。

每个辅助文件都是独立解析的:同名 section(如各 *_params.toml 里的 params) 不会互相覆盖,也没有合并语义。

路径规则:配置里引用的文件路径,绝对路径原样使用;相对路径以主配置 wxserver.toml 所在目录为基准(与 nginx 以 prefix/conf 目录为基准一致), 例如 /etc/wxserver/wxserver.toml 中写 fastcgi_params_file = "fastcgi.toml" 即加载 /etc/wxserver/fastcgi.toml。该规则同样适用于 ssl.cert_file / ssl.key_file / ssl.client_cert_file / include。

文件 用途 引用方式
conf/mime.toml 扩展名 → MIME 静态/DAV 响应自动使用
conf/proxy_params.toml 默认 proxy 请求头 location proxy_params_file
conf/fastcgi.toml FastCGI 参数模板(含 SCRIPT_FILENAME) location fastcgi_params_file
conf/scgi_params.toml SCGI 参数模板 location scgi_params_file
conf/uwsgi_params.toml uWSGI 参数模板 location uwsgi_params_file
conf/waf/crs-lite.toml CRS-lite WAF 规则 waf = { full = { crs = true } } 自动加载

引用示例

http = {
  servers = [{
    domain = ["php.test"],
    listen = [{ addr = ":8080" }],
    locations = [{
      path = "/php",
      type = "fastcgi",
      fastcgi_pass = "127.0.0.1:9000",
      fastcgi_params_file = "fastcgi.toml",
      fastcgi_param = { SCRIPT_FILENAME = "/srv/php/index.php" },
    }],
  }],
}

显式参数表(fastcgi_param/scgi_param/uwsgi_param/proxy_set_header) 在模板之后合并,优先覆盖模板值。参数值支持 $host/$uri/$query_string/ $request_method/$content_type/$content_length/$document_root 等变量。

MIME

conf/mime.toml:

types = {
  html = "text/html",
  woff2 = "font/woff2",
  wxz = "application/x-wxserver-test",
}

运行时优先使用该表,未命中时回退 mime_guess。修改后通过 Manager 保存 或 POST /api/config/reload 生效。

参数模板

fastcgi.toml / proxy_params.toml / scgi_params.toml / uwsgi_params.toml (位于配置目录):

params = {
  QUERY_STRING = "$query_string",
  REQUEST_METHOD = "$request_method",
  SCRIPT_FILENAME = "$document_root$uri",
}

配置转换

wxserver-convert -from auto 会把 include fastcgi_params; / proxy_params / scgi_params / uwsgi_params 转成上面的 *_params_file 引用;include mime.types 被识别为运行时 mime.toml。

← Previous Article Manager 安全配置 Next Article → 外置模块 ABI v2

Comments

No comments yet