<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ### 執行時間和內容[](http://tengine.taobao.org/book/chapter_04.html#id3 "永久鏈接至標題") 過濾(filter)模塊是過濾響應頭和內容的模塊,可以對回復的頭和內容進行處理。它的處理時間在獲取回復內容之后,向用戶發送響應之前。它的處理過程分為兩個階段,過濾HTTP回復的頭部和主體,在這兩個階段可以分別對頭部和主體進行修改。 在代碼中有類似的函數: ngx_http_top_header_filter(r); ngx_http_top_body_filter(r, in); 就是分別對頭部和主體進行過濾的函數。所有模塊的響應內容要返回給客戶端,都必須調用這兩個接口。 ### 執行順序?[](http://tengine.taobao.org/book/chapter_04.html#id4 "永久鏈接至標題") 過濾模塊的調用是有順序的,它的順序在編譯的時候就決定了。控制編譯的腳本位于auto/modules中,當你編譯完Nginx以后,可以在objs目錄下面看到一個ngx_modules.c的文件。打開這個文件,有類似的代碼: ngx_module_t *ngx_modules[] = { ... &ngx_http_write_filter_module, &ngx_http_header_filter_module, &ngx_http_chunked_filter_module, &ngx_http_range_header_filter_module, &ngx_http_gzip_filter_module, &ngx_http_postpone_filter_module, &ngx_http_ssi_filter_module, &ngx_http_charset_filter_module, &ngx_http_userid_filter_module, &ngx_http_headers_filter_module, &ngx_http_copy_filter_module, &ngx_http_range_body_filter_module, &ngx_http_not_modified_filter_module, NULL }; 從write_filter到not_modified_filter,模塊的執行順序是反向的。也就是說最早執行的是not_modified_filter,然后各個模塊依次執行。所有第三方的模塊只能加入到copy_filter和headers_filter模塊之間執行。 Nginx執行的時候是怎么按照次序依次來執行各個過濾模塊呢?它采用了一種很隱晦的方法,即通過局部的全局變量。比如,在每個filter模塊,很可能看到如下代碼: static ngx_http_output_header_filter_pt ngx_http_next_header_filter; static ngx_http_output_body_filter_pt ngx_http_next_body_filter; ... ngx_http_next_header_filter = ngx_http_top_header_filter; ngx_http_top_header_filter = ngx_http_example_header_filter; ngx_http_next_body_filter = ngx_http_top_body_filter; ngx_http_top_body_filter = ngx_http_example_body_filter; ngx_http_top_header_filter是一個全局變量。當編譯進一個filter模塊的時候,就被賦值為當前filter模塊的處理函數。而ngx_http_next_header_filter是一個局部全局變量,它保存了編譯前上一個filter模塊的處理函數。所以整體看來,就像用全局變量組成的一條單向鏈表。 每個模塊想執行下一個過濾函數,只要調用一下ngx_http_next_header_filter這個局部變量。而整個過濾模塊鏈的入口,需要調用ngx_http_top_header_filter這個全局變量。ngx_http_top_body_filter的行為與header fitler類似。 響應頭和響應體過濾函數的執行順序如下所示: ![](https://box.kancloud.cn/2015-08-12_55cb06b1e5fbd.png) 這圖只表示了head_filter和body_filter之間的執行順序,在header_filter和body_filter處理函數之間,在body_filter處理函數之間,可能還有其他執行代碼。 ### 模塊編譯?[](http://tengine.taobao.org/book/chapter_04.html#id5 "永久鏈接至標題") Nginx可以方便的加入第三方的過濾模塊。在過濾模塊的目錄里,首先需要加入config文件,文件的內容如下: ngx_addon_name=ngx_http_example_filter_module HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_example_filter_module" NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_example_filter_module.c" 說明把這個名為ngx_http_example_filter_module的過濾模塊加入,ngx_http_example_filter_module.c是該模塊的源代碼。 注意HTTP_AUX_FILTER_MODULES這個變量與一般的內容處理模塊不同。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看