Skip to content

About

nginx module to call functions in a C library loaded at run time

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

nginx-link-function-module

Build&Test Link function FreeBSD A/UBSan Valgrind Reload CodeQL Lint

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.

Synopsis

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.c

Directives

  • ngx_link_func_lib <path>: the shared library to load for this server; its ngx_link_func_init_cycle runs on worker start and ngx_link_func_exit_cycle on 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).

Building

./configure --add-module=/path/to/nginx-link-function-module

or as a loadable module

./configure --add-dynamic-module=/path/to/nginx-link-function-module

with load_module modules/ngx_http_link_func_module.so; in the main context.

Testing

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/nginx

The 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.

License

BSD 2-Clause, see LICENSE.

About

nginx module to call functions in a C library loaded at run time

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages