美文网首页
nginx第三天,nginx基础概念

nginx第三天,nginx基础概念

作者: ant_1024 | 来源:发表于2018-04-18 22:49 被阅读22次

    nginx基础概念

        1.connection

            a.connection就是对tcp链接的封装,其中包括链接的socket,读写事件,

            b.nginx中的http请求是建立在connection之上的,所以ngin不仅可以作为一个web服务器,也可以作为邮件服务器。

            c.nginx中先获取一个ngx_connection_t结构体,然后创建socket,其中封装着server创建的链接

         d.nginx通过设置worker_connections来设置每个进程可使用的最大链接值

            e.每个worker都有一个独立的链接池

            f.accept_mutex锁控制进程是否添加accept事件。

            g. ngx_http_request_t是对http请求的封装,

         2.nginx如何处理一个完整的请求,对于nginx来说,一个请求是从ngx_http_init_request开始的,然后ngx_http_process_request_line处理请求行,

            通过ngx_http_read_request_header来读取请求数据。调用ngx_http_pares_request_line来解析请求行。当nginx解析到两个回车换行符时,

            就表示请求结束。然后调用ngx_http_process_request来处理请求了。

    ngx_http_process_request会设置当前的链接的读写事件处理函数为ngx_http_request_handler,然后调用ngx_http_handler来真正处理一个完整的http请求。

                nginx的做法是先不读取请求body,所以这里我们设置read_event_handler 为ngx_http_block_reading,即不读取数据。真正读取数据实在ngx_read_hadnler中

            4.nginx将一个请求分为多个阶段,先有ngx_http_core_run_phases生产数据, 最后多嗲用filter来过滤数据,

            5.filter是一个链表结构,filter包括header filter 和body filter , 先执行header filter 中的所有filter,然后再执行bodyfilter中的所有filter。

    相关文章

      网友评论

          本文标题:nginx第三天,nginx基础概念

          本文链接:https://www.haomeiwen.com/subject/rztikftx.html