2018.2.12
初始化阶段:
1.在初始化时,解析"http"配置项,会调用函数ngx_http_block,ngx_http_block函数主要解析配置项,初始化http的一些变量,最后调用ngx_http_optimize_servers创建listening结构
2.ngx_http_optimize_servers 主要功能就是创建listening结构(调用ngx_http_init_listening)
3.ngx_http_init_listening调用ngx_http_add_listening
4.ngx_http_add_listening这个函数会设置监听套接字的回调函数ngx_http_init_connection
连接处理阶段:
1.ngx_http_init_connection首先会设置客户端请求初始化回调函数ngx_http_init_request,然后调用ngx_handle_read_event,把新的套接字放到读事件列表
2.ngx_http_init_request 里会把读的回调函数设置成 ngx_http_process_request_line,以便多次读取时,调用该函数
ngx_http_process_request_line调用ngx_http_parse_request_line解析请求行,如果解析到关键信息,设置解析头的回调函数ngx_http_process_request_headers;
3.ngx_http_process_request_headers解析完头,调用请求处理函数ngx_http_process_request
4.ngx_http_process_request该函数会调用 ngx_http_handler(r);和子请求处理函数ngx_http_run_posted_requests(c);
5.ngx_http_handler调用函数ngx_http_core_run_phases并设置该链接的写回调函数,猜测ngx_http_core_run_phases是各个模块处理数据的函数