ngx_link_func_call

The `ngx_link_func_call` directive invokes a specified function from a dynamically linked application within an NGINX location context.

Syntaxngx_link_func_call "function_name";
Defaultnone
Contextlocation
Arguments1

Description

The ngx_link_func_call directive allows NGINX to call functions defined in dynamically linked libraries, providing the capability to extend NGINX functionality by integrating C/C++ applications. This is particularly useful for applications that require direct interactions with NGINX’s request/response cycle while leveraging external logic or processing features defined outside of NGINX itself.

When this directive is used inside a location block, it expects one argument: the name of the function to be called. This function must match a symbol exported from the shared library specified earlier using the ngx_link_func_lib directive. If the library isn't loaded, or if the function does not exist, an error will occur during the processing of requests to that location.

Additionally, the ngx_link_func_call directive integrates seamlessly with other features like subrequests and caching mechanisms, giving developers flexibility in how their applications are structured and executed. This capability enables modular design where application logic can be handled separately from web server duties, enhancing maintainability and organization.

Config Example

location = /example {
    ngx_link_func_call "example_function";
}

Ensure the mapped function name in the directive matches an exported function in the linked shared library.

Check that the shared library has been properly loaded using the ngx_link_func_lib directive before invoking the function.

Be aware of the function's expected parameters and return types, as mismatches can lead to runtime errors.

← Back to all directives