- 论坛徽章:
- 0
|
大神你好,最近闲来无事的时候我也在阅读nginx代码
有几个问题想向你请教一下
1、关于handler的挂载时机。
看网上的文章大致有两种挂载方式:
(1)在ngx_http_module_t结构体的 postconfiguration
处进行挂载,代码大致如下:
static ngx_int_t
ngx_http_hello_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_CONTENT_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
}
*h = ngx_http_hello_world_handler;
return NGX_OK;
}
(2)在ngx_command_t 结构体的set函数指针处进行挂载,也就是说set函数指针指向的函数完成两件事,
一件事读取配置文件中的值,另一件是挂载handler
请问第二种挂载方式,属于ngnix的那个阶段啊??
当我采用第一种挂载方式的时候,配置文件如下:
location =/kkkk {
hello_world ppppp;
}
可是当我访问/test的时候,该hander怎么也会被调用呢????(url和location也不匹配啊?)
2、想学习一下nginx负载均衡部分是怎么实现,可惜看代码看不太懂,被函数指针弄晕了,
大神能否给指点一下。
回复 2# lenky0401
|
|