Nginx http请求处理流程总结

nginx中对http请求的处理流程如图所示:

       ngx_create_listening()监听server端口,当一旦有人调用connnect连接这个端口时,epoll_wait()->accept();accept返回之后,通过handler回调ngx_http_init_connection初始化一个连接connection; 代码位置:ngx_epoll_module.c:ngx_epoll_process_events()->rev->handler(rev)

走进http请求行处理的函数中,在ngx_http_process_request_line()->ngx_http_process_request()->ngx_http_core_module.c:ngx_http_core_run_phases()

http状态机的11个状态,每一个状态会有对应的handler,在ngx_http_core_run_phases()这个函数里处理这11个状态的handler对应的checker

typedef enum {

    NGX_HTTP_POST_READ_PHASE = 0,

    NGX_HTTP_SERVER_REWRITE_PHASE,  //重定向

    NGX_HTTP_FIND_CONFIG_PHASE,      //find location,http://192.168.72.190:8000/will ,找对应的uri资源;

    NGX_HTTP_REWRITE_PHASE,

    NGX_HTTP_POST_REWRITE_PHASE,

    NGX_HTTP_PREACCESS_PHASE,

    NGX_HTTP_ACCESS_PHASE,

    NGX_HTTP_POST_ACCESS_PHASE,

    NGX_HTTP_PRECONTENT_PHASE,

    NGX_HTTP_CONTENT_PHASE,      //content处理

    NGX_HTTP_LOG_PHASE                //日志的处理;

} ngx_http_phases;

 

存放checker指针的结构体定义

         

 

posted @ 2021-05-16 17:43  will287248100  阅读(398)  评论(0编辑  收藏  举报