Debug log print and conf

Myoungho nginx-forum at forum.nginx.org
Thu Jul 13 07:37:29 UTC 2017


Hello, Im newbie in nginx module developing and now studying how nginx
module works using 'hello_world' module.

I have two questions.

My nginx.conf is; 

        location ~ ^/test1/.*$ {
           error_log /usr/local/nginx/logs/error-helloworld.log debug;
           hello entry1;
        }
 
       location ~ ^/test2/.*$ {
           error_log /usr/local/nginx/logs/error-helloworld.log debug;
           hello  entry2;
        }


1. Where can I see my logs printed by ngx_log_debug*?
   I added following line in handler function.
   ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "hello
world");
   but there is no result in nginx error log nor my_module_error_log.
   and when I use ngx_log_debug1 () function like as follows, there is no
HTTP response. 
   ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "hello
world[%s]", r->args.data);
   ( in confiure, I used --with-debug )

2. How can I get 'entry1' or 'entry2' string in my handler?
my command arrary are here;
static ngx_command_t ngx_http_hello_commands[] = {
{ ngx_string("hello"),
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_hello_loc_conf_t, name),
&ngx_http_hello_p },
ngx_null_command
};

static char *
ngx_http_helloworld(ngx_conf_t *cf, void *post, void *data)
{
	ngx_http_core_loc_conf_t *clcf;
	clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
	clcf->handler = ngx_http_hello_handler;
	ngx_str_t *name = data; // i.e., first field of ngx_http_hello_loc_conf_t

	if (ngx_strcmp(name->data, "") == 0) {
		return NGX_CONF_ERROR;
	}
	hello_string.data = name->data; // --> It's always 'entry2'
	hello_string.len = ngx_strlen(hello_string.data);
        
	return NGX_CONF_OK;
}

whenever I request "http://~~/test/" or "http://~~/test2/"  the hello_string
is always 'entry2'.

Thanks for any helps. 

Myoungho.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,275465,275465#msg-275465



More information about the nginx mailing list