第 1 章 产品简介与快速上手
1.1 产品定位
WxServer 是一款用 Rust 编写的单二进制 Web 服务器与网关。核心能力包括:
- HTTP 引擎:域名匹配、精确/前缀/正则 location、七阶段处理管线、内部重定向与
error_page。 - 代理族:proxy、fastcgi、uwsgi、scgi、grpc、memcached、mirror、WebDAV 与 TCP/UDP stream。
- TLS:SNI 多证书、HTTP/2、HTTP/3(QUIC)、mTLS、ACME 自动证书。
- 安全:SecRule/CRS 规则引擎或 fast 双引擎 WAF、IP 黑白名单、CC 防护、限流、安全响应头、权限分离。
- 运维:内置 Vue 管理后台、Prometheus 指标、combined 访问日志、热重载、跨平台服务管理(
--service)。
1.2 平台与运行用户
| 平台 | 服务管理 | 动态模块 |
|---|---|---|
| Linux | --service 自动检测 systemd/OpenRC(Alpine)/SysV initd |
支持,最稳定 |
| FreeBSD | --service 注册 rc.d(daemon(8)) |
支持 |
| macOS | --service 注册 launchd |
支持 |
| Windows | --service 注册 SCM 服务 |
支持(.dll) |
root 启动且配置 worker_processes >= 1时进入 master/worker 模型,worker 用户为 Linux www-data、macOS _www、FreeBSD www;Windows 服务以普通本地账户运行,不使用 LocalSystem。
1.3 安装布局
Linux 发行版安装后的标准路径:
| 路径 | 内容 |
|---|---|
/usr/sbin/wxserver |
主程序 |
/usr/bin/wxserver-convert |
Web 服务器 / CRS 配置转换工具(`–from auto |
/usr/bin/wxserver-tool |
htpasswd、bench 压测、precompress 预压缩 |
/etc/wxserver/ |
wxserver.toml、manager.toml、acme.toml、cert.toml |
/etc/wxserver/vhost/ |
站点文件,默认 default.toml |
/etc/wxserver/certs/ |
证书与私钥 |
/var/wxserver/html/ |
默认站点根目录与错误页模板 |
/var/log/wxserver/ |
访问、错误、WAF、stream 日志 |
/usr/share/wxserver/modules/ |
外置模块 |
/var/run/wxserver/ |
PID、共享内存、缓存等运行时文件 |
macOS 与 FreeBSD 的程序文件使用 /usr/local 前缀(/usr/local/bin、/usr/local/sbin、/usr/local/share/wxserver/modules),配置与 Linux 相同固定在 /etc/wxserver;站点根目录、日志与运行目录与 Linux 相同,仍为 /var/wxserver/html、/var/log/wxserver、/var/run/wxserver。Windows 安装目录固定包含 bin\、sbin\、conf\、html\、logs\、modules\、run\,四份 TOML 与 vhost\、certs\ 位于 conf\;服务账户为普通本地用户。
1.4 首次启动
wxserver -t -c /etc/wxserver/wxserver.toml # 校验配置
wxserver -c /etc/wxserver/wxserver.toml # 前台启动
wxserver --service install -c /etc/wxserver/wxserver.toml # 注册系统服务
wxserver --service start -c /etc/wxserver/wxserver.toml
wxserver -s reload|stop|quit -c /etc/wxserver/wxserver.toml # 信号控制
首次启动时,如果 manager.toml 中没有用户,程序会创建 admin 账户、生成 16 位随机密码,打印到 stdout 并写入 manager.toml(0600)。浏览器打开 http://127.0.0.1:9090,用该口令登录后立即修改密码;忘记口令可执行:
wxserver --reset-password 'new-password' -c /etc/wxserver/wxserver.toml
wxserver --reset-totp -c /etc/wxserver/wxserver.toml
管理后台默认只监听回环地址。确需远程访问时,应通过 SSH 隧道或前置反向代理,并启用强口令与 TOTP。
1.5 外置模块部署
外置模块为原生动态库(cdylib),按平台为 .so/.dylib/.dll,在主配置 external_modules 段声明路径后随配置加载:
cargo build --release --manifest-path /path/to/module/Cargo.toml
external_modules = [{ path = "/usr/share/wxserver/modules/libexample.so", enabled = true }]
可选 SHA-256 哈希固定与 Ed25519 签名校验;详见第 8 章。