wasmtime

The 'wasmtime' directive is used to define and manage WebAssembly modules within the NGINX configuration to extend its capabilities.

Syntaxwasm { module name path.to.wasm; }
Defaultnone
Context
Argumentsnone

Description

The 'wasmtime' directive enables NGINX to interface with WebAssembly (Wasm) modules, allowing developers to extend the functionality of NGINX through custom implementations written in programming languages that compile to Wasm, such as Rust or Go. This interaction is achieved via the Proxy-Wasm ABI, which NGINX utilizes to load and execute Wasm modules at runtime. The directive itself does not take any arguments, but it is typically used in conjunction with other directives to configure the WebAssembly environment for NGINX instances.

When using the 'wasmtime' directive, it initiates a new top-level configuration block for Wasm modules. Within this block, developers define individual modules that can be used as filters or auxiliary functions in various phases of request processing. This modularity allows for the dynamic application of complex logic directly in the data path of the server, enhancing its capabilities beyond traditional configurations. For example, a developer can specify a Wasm module that implements specialized authentication, rate limiting, or even data transformation features. Additionally, NGINX worker processes can each instantiate the specified Wasm modules, allowing for concurrent processing and high throughput.

Config Example

wasm {
    module my_filter /path/to/my_filter.wasm;
}

Ensure the Wasm binary is correctly compiled and compatible with the Proxy-Wasm ABI.

Path to the Wasm module must be accessible by NGINX and have appropriate permissions set.

Be cautious with resource limits, as Wasm execution could impact the performance of NGINX if not properly managed.

← Back to all directives