Dynamic module and obtaining http core module configuration

Maxim Dounin mdounin at mdounin.ru
Wed Aug 17 23:44:59 UTC 2016


On Wed, Aug 10, 2016 at 12:09:54PM +0300, Rūdolfs Bundulis wrote:

> Hi,
> I am trying to make a dynamic nginx module. After reading all the tutorials
> and stuff available I set up a working minimal sample and started hooking
> up my http handlers. The question that arose is, in the static modules the
> http module configuration is retrieved like this (in a lets say
> postconfiguration handler):
> static ngx_int_t postconfiguration_handler(ngx_conf_t* cf)
> {
> ngx_http_core_main_conf_t* nginx_http_configuration =
> reinterpret_cast<ngx_http_core_main_conf_t*>(ngx_http_conf_get_module_main_conf(cf,
> ngx_http_core_module));
>         ...
> If I'm not overlooking something this will not work (and in my case does
> not) with a dynamic module
> the ngx_http_core_module.ctx_index is not initialized since the initialized
> version of ngx_http_core_module lives inside nginx.exe (where it is set by
> ngx_count_modules) and my dll does not see that. If could run through the
> module list and find what I need, but I just wanted to know if there is a
> better solution already in place.

The ngx_http_core_module symbol from the main binary is expected 
to be available in modules as well, imported there from the main 
binary.  This is how it works on Unix.

On the other hand, on Windows there may be unexpected effects.  We 
don't really support dynamic modules on Windows now - they can be 
only build using mingw-gcc with "-Wl,--export-all-symbols", and 
I've seen reports that "--export-all-symbols" may produce 
incorrect code in some cases.

If you are trying to make nginx modules, consider doing this on 
Unix, not on Windows.

Maxim Dounin

More information about the nginx-devel mailing list