Chapter 8 — Modules
8.1 Built-in modules
Built-in modules are compiled into the main binary; their configuration
lives under modules.<name> or as top-level location keys. By purpose:
| Category | Modules |
|---|---|
| HTTP core | http_staticfile, http_proxy, http_rewrite, http_headers, http_accesslog |
| Protocol clients | http_fastcgi, http_uwsgi, http_scgi, http_grpc, http_memcached |
| Security | http_waf, http_access, http_auth_basic, http_auth_request, http_auth_jwt, http_secure_link, http_security_headers, http_limit, http_error_guard |
| Filters and compression | http_gzip, http_gunzip, http_brotli, http_zstd, http_sub, http_addition, http_ssi, http_charset, http_minify, http_concat |
| Media and content | http_image_thumb, http_mp4, http_empty_gif, http_stub_status, http_nchan, http_upload |
| Variables and splitting | http_map, http_geo, http_geoip, http_split_clients, http_realip, http_userid, http_browser, http_referer |
| Observability and protection | http_otel, http_logsink, http_mirror, http_sysguard |
Modules are listed with name, version, description and load state at
GET /api/modules and on the “Modules” page of the console.
8.2 External dynamic modules
External modules are native dynamic libraries (cdylib): .so on
Linux/FreeBSD, .dylib on macOS and .dll on Windows, loaded through the
stable C ABI v2 — the module exports a wxserver_module_v2 symbol
(manifest JSON + on_hook callback) and, optionally,
wxserver_body_filter_v1 (streaming body filter) and wxserver_action_v1
(console actions).
Build any Rust crate as a cdylib:
cargo build --release --manifest-path /path/to/plugin/Cargo.toml
# output: target/release/lib<name>.so / .dylib / .dll
Enable it in configuration and pass the module’s global settings (validated against the manifest’s config schema):
external_modules = [{ path = "/usr/share/wxserver/modules/libexample.so", enabled = true }]
modules = { example = { greeting = "hi" } }
The manifest declares the module’s hooks, activation conditions,
configuration schema and console forms/i18n; the host validates the
manifest, dependencies (depends; a missing required dependency fails
startup) and scoped configuration. Optional sha256 pinning and
signature/signature_key Ed25519 verification are available (public keys
under plugin_trust.keys). Adding or removing a module takes effect on
configuration reload. A sample plugin lives in plugins/example_echo/ in
the source tree. C ABI details: docs/plugin-abi-c.md.
8.3 Module development interface
Built-in modules live in modules/<name>/ crates: they declare their
manifest with the modules/common helpers, implement the hook trait for
their phase and self-register via register_entry! (linkme distributed
slice). External modules implement the same manifest model over the C ABI.
Calling conventions by phase:
| Phase | Trait / mechanism | Typical use |
|---|---|---|
| Rewrite | BuiltinHandler / AsyncBuiltinHandler |
Path rewrite, redirect |
| PreAccess / Access | Same | Rate limiting, authentication, IP control |
| Content | ContentBuiltin (dispatched by location.type) |
Proxy, FastCGI, static files |
| HeaderFilter | BuiltinHandler |
Header filters |
| BodyFilter | BuiltinHandler / AsyncBodyBuiltin / external wxserver_body_filter_v1 |
Compression, substitution, SSI |
| Log | BuiltinHandler (with LogMeta) |
Access logging |
| WAF | Phase::WafRequest/WafResponse | Blocking (returns blocked) |
| service | ServiceBuiltin (started by plugin::start_services) |
metrics/otel/stream/mail |
The phase order is fixed: Rewrite → PreAccess → Access → Content →
HeaderFilter → BodyFilter → Log. Hooks declare conditions
(methods/path/host/header/cookie/status/tls/cidr) and priority; HookOutcome
is Continue / Handled(Resp) / InternalRedirect. Design:
docs/plugin-architecture.md; implementation status:
docs/plugin-architecture.md.
8.4 Disabling modules
Built-in modules can be disabled at runtime without rebuilding:
http = {
disabled_modules = ["http_waf", "http_zstd"],
servers = [{ disabled_modules = ["http_image_thumb"] }],
}
A disabled module stops running its phases and content handler. Disabling a content module requires removing every location.type that references it, otherwise wxserver -t and console saves fail validation. Runtime disabling does not force-release resources already initialized by the module; restart the process to reclaim them. When a required dependency is disabled, startup fails; an optional dependency only warns.