上一篇完成配置文件的解析,但是仅仅解析完配置还是不够的,还有后续的一些处理,这篇大致看看这些处理过程
一、module配置初始化
主要是ngx_http_core_init_main_conf设置一些参数值;
ngx_http_upstream_init_main_conf完成ngx_http_upstream_headers_in创建hash表;其他的没细看
二、http域配置合并
在http{}块中,可嵌套多个server{},server{}中可嵌套多个location,NGINX为了简化配置,有些配置作用域横跨http块,server块,location块,可在http块最外层,配置多个server{},多个location{}共同使用的配置,也可在server块内配置多个location{}共同使用的配置。如sendfile、default_type就是属于作用域横跨多个块的配置:
由上一篇可得知http域配置的结构:
主要看下ngx_http_merge_servers及ngx_http_core_module_ctx提供的merge方法:
举个例子说明:
以sendfile为例,该配置是可配置在http块,server块,location块的loc_conf
http{
sendfile on;
server{
sendfile off;
location /{
}
location /test{
}
}
server{
location /{
sendfile off;
}
location /test{
}
}
}
//当server{}和location{}都没有配置sendfile的时候,http层配置sendfile将一层层往下merge到server层,location层,
//但是当server层或者location层已经配置了该参数,那么merge不会改变下一层的参数的值。所以优先级:最下层>上一层>默认值。
//多个同级server或者多个同级location之间不会相互影响。
三、ngx_http_init_locations与ngx_http_init_static_location_trees创建locating树NGINX源码之:location
三、ngx_http_init_headers_in_hash与ngx_http_variables_init_vars
这两个方法分别将ngx_http_headers_in和ngx_http_core_variables以hash表方式组织并存入main_conf中。hash表的组织,之前的篇章有详细介绍,这里就不记录了。
四、ngx_http_init_phases,phases初始化与使用,这部分内容比较多,考虑另立篇章记录请求处理十一个阶段
五、ngx_http_optimize_servers
ngx_http_optimize_servers与server{}中listen指令,socket启动等是配合一起的一系列动作,这部分也考虑另立篇章NGINX源码之:listen和server_name命令与listening监听创建。