This module lets nginx hand a request to a function in a C library you load at run time, so you can serve a location straight from your own compiled code without writing an nginx module. It is a maintained fork of Taymindis/nginx-link-function.
http {
server {
# the application library, loaded once per worker
ngx_link_func_lib "/etc/nginx/liblinkfuntest.so";
location = /greeting {
ngx_link_func_call "my_app_simple_get_greeting";
}
}
}The library is an ordinary shared object built against the module header
src/ngx_link_func_module.h; a worked example is in
build_test_resources/linkfuntest.c:
cc -shared -fPIC -I /path/to/nginx-link-function-module/src \
-o liblinkfuntest.so linkfuntest.cngx_link_func_lib <path>: the shared library to load for this server; itsngx_link_func_init_cycleruns on worker start andngx_link_func_exit_cycleon exit.ngx_link_func_call "<function>": dispatch this location to the named function in the library.ngx_link_func_shm_size <size>: size of the shared-memory zone the API offers to applications.
See the upstream documentation for the full application API (request body and args, response and headers, shared memory, subrequests).
./configure --add-module=/path/to/nginx-link-function-moduleor as a loadable module
./configure --add-dynamic-module=/path/to/nginx-link-function-modulewith load_module modules/ngx_http_link_func_module.so; in the main
context.
ci/build.sh 1.30.5 /tmp/nginx-test
TEST_NGINX_BINARY=/tmp/nginx-test/sbin/nginx prove -r t/
ci/link.sh /tmp/nginx-test/sbin/nginx
ci/reload.sh /tmp/nginx-test/sbin/nginxThe t/ suite needs only core Perl and a C compiler; the nginx core
Test::Nginx is vendored under t/lib. ci/link.sh needs curl and a C
compiler to build the sample library.
BSD 2-Clause, see LICENSE.