ngx_link_func_lib

The ngx_link_func_lib directive specifies the shared library for dynamic linking with NGINX applications.

Syntaxngx_link_func_lib path_to_shared_library;
Defaultnone
Contextserver
Arguments1

Description

The ngx_link_func_lib directive allows users to specify the path to a shared library (for example, a .so file) that the NGINX server will dynamically link to and use for function calls. This module is particularly useful for integrating C/C++ applications with NGINX to handle requests by executing functions defined in the shared library. When this directive is declared within the server context, it establishes the library that will be available for later calls made through the ngx_link_func_call directive.

When the library path is provided, NGINX will load the shared library at runtime. This gives the ability to invoke functions from the specified library in response to requests at defined endpoints. Each server can link to different libraries, allowing for modularity in application design, while all shares the same memory for interprocess communication if the same library path is used across multiple servers.

To ensure functionality, the library must be accessible by the NGINX process and properly handle function definitions as expected by the configured directives and their usage. This feature emphasizes on performance and responsiveness by allowing heavy lifting tasks to be executed outside of the NGINX core, taking advantage of optimized C/C++ functions.

Config Example

server {
    listen 8888;
    ngx_link_func_lib "/path/to/your/libcfuntest.so";
}

location = /testCFunGreeting {
    ngx_link_func_call "my_app_simple_get_greeting";
}

Ensure the specified library exists and is accessible by the NGINX worker processes.

The functions in the shared library must match the expected signatures as defined in the NGINX module to avoid runtime errors.

Careful consideration should be taken regarding the thread-safety of the shared library functions if using NGINX in a threaded mode.

← Back to all directives