### 模塊編譯順序[](http://tengine.taobao.org/book/chapter_09.html#id1 "永久鏈接至標題")
上一節中,提到過,nginx模塊的順序很重要,會直接影響到程序的功能。而且,nginx和部分模塊,也有著自己特定的順序要求,比如ngx_http_write_filter_module模塊一定要在filter模塊的最后一步執行。想查看模塊的執行順序,可以在objs/ngx_modules.c這個文件中找到,這個文件在configure之后生成,上一節中,我們看過這個文件里面的內容。
下面是一個ngx_modules.c文件的示例:
[](http:// "點擊提交Issue,反饋你的意見...")
ngx_module_t *ngx_modules[] = {
// 全局core模塊
&ngx_core_module,
&ngx_errlog_module,
&ngx_conf_module,
&ngx_emp_server_module,
&ngx_emp_server_core_module,
// event模塊
&ngx_events_module,
&ngx_event_core_module,
&ngx_kqueue_module,
// 正則模塊
&ngx_regex_module,
// http模塊
&ngx_http_module,
&ngx_http_core_module,
&ngx_http_log_module,
&ngx_http_upstream_module,
// http handler模塊
&ngx_http_static_module,
&ngx_http_autoindex_module,
&ngx_http_index_module,
&ngx_http_auth_basic_module,
&ngx_http_access_module,
&ngx_http_limit_conn_module,
&ngx_http_limit_req_module,
&ngx_http_geo_module,
&ngx_http_map_module,
&ngx_http_split_clients_module,
&ngx_http_referer_module,
&ngx_http_rewrite_module,
&ngx_http_proxy_module,
&ngx_http_fastcgi_module,
&ngx_http_uwsgi_module,
&ngx_http_scgi_module,
&ngx_http_memcached_module,
&ngx_http_empty_gif_module,
&ngx_http_browser_module,
&ngx_http_upstream_ip_hash_module,
&ngx_http_upstream_keepalive_module,
//此處是第三方handler模塊
// http filter模塊
&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,
// 第三方filter模塊
&ngx_http_copy_filter_module,
&ngx_http_range_body_filter_module,
&ngx_http_not_modified_filter_module,
NULL
};
http handler模塊與http filter模塊的順序很重要,這里我們主要關注一下這兩類模塊。
http handler模塊,在后面的章節里面會講到多階段請求的處理鏈。對于content phase之前的handler,同一個階段的handler,模塊是順序執行的。比如上面的示例代碼中,ngx_http_auth_basic_module與ngx_http_access_module這兩個模塊都是在access phase階段,由于ngx_http_auth_basic_module在前面,所以會先執行。由于content phase只會有一個執行,所以不存在順序問題。另外,我們加載的第三方handler模塊永遠是在最后執行。
http filter模塊,filter模塊會將所有的filter handler排成一個倒序鏈,所以在最前面的最后執行。上面的例子中,&ngx_http_write_filter_module最后執行,ngx_http_not_modified_filter_module最先執行。注意,我們加載的第三方filter模塊是在copy_filter模塊之后,headers_filter模塊之前執行。
- 上篇:nginx模塊開發篇
- nginx平臺初探
- 初探nginx架構
- nginx基礎概念
- connection
- request
- keepalive
- pipe
- lingering_close
- 基本數據結構
- ngx_str_t
- ngx_pool_t
- ngx_array_t
- ngx_hash_t
- ngx_hash_wildcard_t
- ngx_hash_combined_t
- ngx_hash_keys_arrays_t
- ngx_chain_t
- ngx_buf_t
- ngx_list_t
- ngx_queue_t
- nginx的配置系統
- 指令參數
- 指令上下文
- nginx的模塊化體系結構
- 模塊的分類
- nginx的請求處理
- handler模塊
- handler模塊簡介
- 模塊的基本結構
- 模塊配置結構
- 模塊配置指令
- 模塊上下文結構
- 模塊的定義
- handler模塊的基本結構
- handler模塊的掛載
- handler的編寫步驟
- 示例: hello handler 模塊
- handler模塊的編譯和使用
- 更多handler模塊示例分析
- http access module
- http static module
- http log module
- 過濾模塊
- 過濾模塊簡介
- 過濾模塊的分析
- upstream模塊
- upstream模塊
- upstream模塊接口
- memcached模塊分析
- 本節回顧
- 負載均衡模塊
- 配置
- 指令
- 鉤子
- 初始化配置
- 初始化請求
- peer.get和peer.free回調函數
- 本節回顧
- 其他模塊
- core模塊
- event模塊
- 模塊開發高級篇
- 變量
- 下篇:nginx原理解析篇
- nginx架構詳解
- nginx的源碼目錄結構
- nginx的configure原理
- 模塊編譯順序
- nginx基礎設施
- 內存池
- nginx的啟動階段
- 概述
- 共有流程
- 配置解析
- nginx的請求處理階段
- 接收請求流程
- http請求格式簡介
- 請求頭讀取
- 解析請求行
- 解析請求頭
- 請求體讀取
- 讀取請求體
- 丟棄請求體
- 多階段處理請求
- 多階段執行鏈
- POST_READ階段
- SERVER_REWRITE階段
- FIND_CONFIG階段
- REWRITE階段
- POST_REWRITE階段
- PREACCESS階段
- ACCESS階段
- POST_ACCESS階段
- TRY_FILES階段
- CONTENT階段
- LOG階段
- Nginx filter
- header filter分析
- body filter分析
- ngx_http_copy_filter_module分析
- ngx_http_write_filter_module分析
- subrequest原理解析
- https請求處理解析
- 附錄A 編碼風格
- 附錄B 常用API
- 附錄C 模塊編譯,調試與測試