Installing handlers in NGX_HTTP_LOG_PHASE

Piotr Sikora piotr.sikora at
Wed Dec 23 13:42:15 MSK 2009

> However, what I want to achieve is to install the handler
> conditionally. So when you in your nginx.conf say:
> location /
>    perl_log_handler MyModule::log_handler
> I tried the following approach and failed:
> static ngx_command_t  ngx_http_perl_commands[] = {
>    ....
>    { ngx_string("perl_log_handler"),
>      ngx_http_perl_handler_init,
>      0,
>      NULL },
>    ....
> };

ngx_http_perl_handler_init should stay in postconfiguration init phase. What 
you should do to use this feature conditionally is to use yourcf->enable 
flag (for working example check ngx_http_autoindex_module.c).

This is because you don't set new handler but you are adding new one to the 
processing chain and your handler will be called for every single request 
(so you must return NGX_DECLINE as soon as possible when it isn't enabled).

Best regards,
Piotr Sikora < piotr.sikora at >

More information about the nginx-devel mailing list