nginx源代码执行过程(一)

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是各个模块处理数据的函数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值