proxy_wasm
The `proxy_wasm` directive integrates WebAssembly modules into the NGINX request processing pipeline.
Description
The proxy_wasm directive allows developers to specify a WebAssembly (WASM) module that will execute as part of the HTTP request and response processing stages in NGINX. This integration is made possible through the Proxy-Wasm ABI, which standardizes how WASM filters can interact with NGINX's underlying server architecture. By implementing WASM modules, users can extend NGINX's capabilities by adding custom processing logic, such as authentication, logging, or request modification in a performant manner without needing to change the core NGINX codebase.
The proxy_wasm directive can accept one or two arguments. The first argument is the name of the WASM module to execute, while the second argument, which is optional, can be used to specify the execution phase where the module should be invoked. If no phase is provided, it defaults to the default phase. This design provides flexibility, allowing developers to customize their request handling based on their specific application needs. The lifecycle of a WASM module is tightly controlled by NGINX, ensuring that modules are loaded once per worker process, which optimizes resource use.
Additionally, using this directive in conjunction with other configurations like wasm_call can increase the modularity and reusability of WebAssembly components across NGINX configurations.
Config Example
http {
server {
listen 9000;
location / {
proxy_wasm my_custom_filter;
proxy_pass http://upstream;
}
}
}Make sure the specified WASM module path is correctly defined and accessible to NGINX processes.
Check compatibility of the WASM module with the NGINX version being used.
Ensure that the phases in which the WASM module operates are appropriate for the intended processing logic.