module

The module directive defines WebAssembly modules to be utilized within NGINX, facilitating the execution of custom business logic within NGINX's processing pipeline.

Syntaxmodule name path.to.module.{wasm|wat};
Defaultnone
Context
Arguments2-3

Description

The module directive is used within the wasm block in NGINX, signaling the inclusion of WebAssembly modules that extend NGINX functionality. Each instance of this directive specifies a unique name followed by the path to the WebAssembly binary file (.wasm) or a text file (.wat). When the NGINX server starts, it compiles and instantiates the specified module, enabling it for use in proxy filtering or other phases of request processing.

The first argument is the name, which serves as a reference identifier for the module within the NGINX configuration. The second argument is the path to the WebAssembly file required to load the module. An optional third argument can be included to specify additional options, but this remains less common. Upon successful loading, these modules can implement specific features or logic defined by the WebAssembly code, enhancing the NGINX server's capabilities like traffic management, data transformation, or custom logging.

It is crucial to ensure that the specified paths are correct and that the WebAssembly module does not violate the expected ABI (Application Binary Interface) of the Proxy-Wasm standard, as this could lead to runtime failures or incorrect behavior during NGINX operation.

Config Example

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

Ensure that the path to the WebAssembly file is correct and accessible by the NGINX user.

Modules should follow the Proxy-Wasm ABI to prevent runtime errors.

When debugging, ensure that you are using a NGINX build with debugging support enabled.

← Back to all directives