nginx处理http请求完整流程
2018-04-02 18:11
344 查看
在nginx的worker进程启动后,便阻塞在epoll_wait函数(ngx_epoll_process_events),等待http请求的到来,那么当一个http请求到来之时,nginx是如何作出相应的呢?下面介绍该过程。 首先,在ngx_event_process_init函数中,可看到rev->handler被初始化为函数ngx_event_accept,因此,在函数ngx_epoll_process_events中,对rev->handler的调用会调到ngx_event_accept函数。该函数会调用ls->handler(c),这个handler又是在哪里初始化的呢?该函数是在ngx_http_add_listening中进行初始化的,具体语句为:ls->handler= ngx_http_init_connection,因此最终会在ngx_http_init_connection中,一步一步调用至ngx_http_core_run_phases,该函数中,会遍历所有的11个阶段,若该阶段有挂载函数,则会调用该函数。 具体而言,以ngx_http_static_module为例,该模块挂载在NGX_HTTP_CONTENT_PHASE中,因此当NGX_HTTP_CONTENT_PHASE到来时,会调用ngx_http_static_handler函数,该函数中会调用ngx_http_send_header,以及ngx_http_output_filter函数,这两个函数最终会调用ngx_http_write_filter函数,在该函数中会调用ngx_linux_sendfile_chain函数发送数据。
相关文章推荐
- Nginx源码阅读(worker进程处理http请求流程)
- nginx处理http请求流程
- nginx处理流程
- HttpHand和HttpModule的详细解释,包括Asp.Net对Http请求的处理流程。
- asp.net HttpHand和HttpModule的详细解释,包括Asp.Net对Http请求的处理流程。
- Nginx HTTP请求流程
- Nginx HTTP请求流程
- libgdx一个完整的处理流程
- Nova API服务 之 处理HTTP请求的流程
- 阿里云ECS之完整流程搭建:CentOS 7.3+Nginx 1.12.1+php 7.1 + MaraiaDB 5.5.52 + PhpMyAdmin 4.6.6
- nginx一般的http请求建立处理,发送函数调用,以及各个phase的状态(等完善)
- Servlet处理Http请求的执行过程(Servlet核心流程)
- Nginx学习之十一-Nginx启动框架处理流程
- Nginx HTTP请求流程
- Nginx HTTP请求流程
- Nginx中http请求的处理过程
- Nginx学习之十一-Nginx启动框架处理流程
- Nginx学习之十一-Nginx启动框架处理流程
- nginx学习笔记六(Nginx事件框架处理流程)
- 文章18 :Nginx中http请求的处理过程