Nginx学习(6)—http配置模型
来源:互联网 发布:陕汽重卡软件 编辑:程序博客网 时间:2024/05/01 13:11
HTTP配置模型
ngx_http_conf_ctx_t结构体
- typedef struct {
- /* 三个指针数组,数组中每个元素分别指向由create_main/srv/loc_conf方法产生的配置结构体 */
- void **main_conf;
- void **srv_conf;
- void **loc_conf;
- } ngx_http_conf_ctx_t;
- static char *
- ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
- {
- ...
- /* HTTP模块创建ngx_http_conf_ctx_t结构体 */
- ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
- if (ctx == NULL) {
- return NGX_CONF_ERROR;
- }
- http_ctx = cf->ctx;
- ctx->main_conf = http_ctx->main_conf;
- /* the server{}'s srv_conf */
- /* 生成一个srv指针数组存储所有srv配置 */
- ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
- if (ctx->srv_conf == NULL) {
- return NGX_CONF_ERROR;
- }
- /* the server{}'s loc_conf */
- /* 生成一个loc指针数组存储所有srv里的loc配置 */
- ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
- if (ctx->loc_conf == NULL) {
- return NGX_CONF_ERROR;
- }
- /* 遍历所有HTTP模块 */
- for (i = 0; ngx_modules[i]; i++) {
- if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
- continue;
- }
- module = ngx_modules[i]->ctx;
- /* 如果遍历的该模块实现了srv/loc方法,则调用,并将返回的地址存储到srv/loc指针数组中 */
- if (module->create_srv_conf) {
- mconf = module->create_srv_conf(cf);
- if (mconf == NULL) {
- return NGX_CONF_ERROR;
- }
- ctx->srv_conf[ngx_modules[i]->ctx_index] = mconf;
- }
- if (module->create_loc_conf) {
- mconf = module->create_loc_conf(cf);
- if (mconf == NULL) {
- return NGX_CONF_ERROR;
- }
- ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
- }
- }
- ...
- }
解析HTTP配置流程
画下书中流程,梳理梳理。
HTTP配置模型的内存布局
还是直接画上书中的解释图,一看就明白的东西。这种内存布局设计对生成的ngx_http_XXX_conf_t配置结构体的存储以及对配置文件的解析做了相当好的解释。
如何合并配置项
还是直接画下解析完http配置后的配置合并流程图。
总结
几个图说的清清楚楚。另外,本章还有error日志以及请求上下文两节。error日志就是打印信息函数的实现以及error的级别的介绍。所谓的请求上下文也是再熟悉不过了。之前所在实习公司的全新系统架构中,用的就是全异步的请求机制,对请求上下文这东西,是相当的感性了。然后,现在专注书中设计及业务流程上的学习,之后再此基础上开始做源码的分析。
0 0
- Nginx学习(6)—http配置模型
- Nginx学习笔记(七):HTTP配置模型
- 【Nginx】HTTP配置模型
- Nginx学习(5)—Http配置(1)
- Nginx学习(5)—http配置(2)
- Nginx学习(5)—http配置(3)
- Nginx学习——http配置项解析编程
- Nginx学习之HTTP-2.0配置
- nginx http代理配置
- Nginx配置Http文件服务器
- Nginx之http配置
- Nginx学习——Nginx基本配置
- Nginx学习笔记(五):怎样使用HTTP配置(上)
- Nginx学习笔记(六):怎样使用HTTP配置(下)
- Nginx学习(2)—配置
- Nginx 作为Http代理服务器配置
- ubuntu nginx配置HTTP Authentication
- 【Nginx】如何处理HTTP配置
- Hadoop 中利用 mapreduce 读写 mysql 数据
- hibernate学习笔记
- Hibernate乐观锁与悲观锁的使用(并发)
- ASP FSO相关的一些例子
- Java中的接口
- Nginx学习(6)—http配置模型
- openwrt SDK, 利用SDK生成自己的ipk安装包
- C/C++视频
- oracle 联机日志文件损坏的几种场景和恢复方法
- C++中extern “C”含义深层探索
- 宿舍来了个小伙伴,也带来一个神器
- error 102: Invalid namespace http://ns.adobe.com/air/extension/4.0
- asp.net做篮球比赛抽签功能
- 哈哈