Srebrenko Šehić
December 23, 2009 04:50AM
Hi list,

I'm looking into expanding nginx' Perl hooks to support installing
handlers for all NGX_HTTP phases. Ultimate goal is to have nginx' Perl
hooks do all those fancy things Apache's mod_perl can. Like rewriting
URI, filtering/changing proxied response bodies, etc. As starters, I
want to implement a handler which will run some Perl code in
NGX_HTTP_LOG_PHASE. I do, however, have some questions that I hope
someone can shed some light onto:

If I register a postconfiguration hook, I'm able to install a handler
at LOG_PHASE phase:

static ngx_http_module_t ngx_http_perl_module_ctx = {
....
ngx_http_perl_log_init, /* postconfiguration */
....
};

static ngx_int_t
ngx_http_perl_log_init(ngx_conf_t *cf)
{
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;

cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);

h = ngx_array_push(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
}

*h = ngx_http_perl_log_handler;

return NGX_OK;
}

Above works just fine.

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_LOC_CONF|NGX_HTTP_LMT_CONF|NGX_CONF_TAKE1,
ngx_http_perl_handler_init,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
....
};

static char *
ngx_http_perl_handler_init(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;

cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);

h = ngx_array_push(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers);
if (h == NULL) {
return NGX_CONF_ERROR;
}

*h = ngx_http_perl_log_handler;

return NGX_CONF_OK;
}

nginx dies with SIGSEGV upon startup.

What is the correct approach to conditionally install a handler?

Thanks,
Srebrenko

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Installing handlers in NGX_HTTP_LOG_PHASE

Srebrenko Šehić 3404 December 23, 2009 04:50AM

Re: Installing handlers in NGX_HTTP_LOG_PHASE

Maxim Dounin 973 December 23, 2009 05:08AM

Re: Installing handlers in NGX_HTTP_LOG_PHASE

Srebrenko Šehić 963 December 23, 2009 07:54AM

Re: Installing handlers in NGX_HTTP_LOG_PHASE

Maxim Dounin 1348 December 23, 2009 08:46AM

Re: Installing handlers in NGX_HTTP_LOG_PHASE

Piotr Sikora 987 December 23, 2009 05:44AM

Re: Installing handlers in NGX_HTTP_LOG_PHASE

Srebrenko Šehić 882 December 23, 2009 07:56AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 62
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready