Nginx handle的两种挂载方式
2016-02-03 17:25
621 查看
Nginx handle的两种挂载方式。
}
二:按需求添加
这种方式只能在NGX_HTTP_CONTENT_PHASE阶段执行,ngx_http_core_content_phase执行时,优先处理这种挂载。一旦判断有这种挂载存在,第一种的挂载handle将不会被执行。
ngx_http_update_location_config 中有会把handle赋值给content_handler.ngx_http_request_t->content_handler = clcf->handler;
然后执行的时优先执行这种挂载。
一:按阶段挂载
这种挂载是在postconfiguration函数执行时添加到ngx_http_core_main_conf_t. phases[]. handlers里。static ngx_http_module_t ngx_http_hello_module_ctx = { NULL, /* preconfiguration */ ngx_http_hello_init, /* postconfiguration */ NULL, /* create main configuration */ NULL, /* init main configuration */ NULL, /* create server configuration */ NULL, /* merge server configuration */ ngx_http_hello_create_loc_conf, /* create location configuration */ NUL
}
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); //取得core_module的cf h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers); // 挂载函数到对应处理阶段 if (h == NULL) { return NGX_ERROR; } *h = ngx_http_hello_handler; //将函数指针指向handler函数 return NGX_OK; }
二:按需求添加
static char * ngx_http_mytest(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_loc_conf_t *clcf; clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_mytest_handler; return NGX_CONF_OK; }
这种方式只能在NGX_HTTP_CONTENT_PHASE阶段执行,ngx_http_core_content_phase执行时,优先处理这种挂载。一旦判断有这种挂载存在,第一种的挂载handle将不会被执行。
ngx_http_update_location_config 中有会把handle赋值给content_handler.ngx_http_request_t->content_handler = clcf->handler;
然后执行的时优先执行这种挂载。
ngx_int_t ngx_http_core_content_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph) { size_t root; ngx_int_t rc; ngx_str_t path; if (r->content_handler) { r->write_event_handler = ngx_http_request_empty_handler; ngx_http_finalize_request(r, r->content_handler(r)); return NGX_OK; }
相关文章推荐
- Nginx+Mysql+php 安装步骤
- LNMP 安装及配置
- 在Linux上使用web2py_uwsgi_nginx搭建web服务器
- fastdfs-nginx-module安装
- nginx的使用
- Nginx部署
- thinkphp 在 nginx 中配置 (rewrite)
- 转帖一下《深入理解Nginx》在线支持网站的勘误,访问太慢了
- Nginx安装与使用
- Nginx深入详解之upstream分配方式
- CentOS+Nginx+PHP+MySQL配置教程(图解)
- Nginx配置
- Nginx配置详解
- Nginx正向代理
- nginx配置location总结及rewrite规则写法
- Ubuntu14.04安装nginx稳定版本步骤
- Nginx和apache 配置
- Nginx详解-服务器集群
- 详解在使用CDN加速时Nginx获取用户IP的配置方法
- 基于nginx实现protobuf RPC