參考資料《深入理解nginx>
乙個nginx.conf的例子
核心結構體ngx_http_conf_ctx_t
管理main級別下的配置項在處理http{}塊內的main級別配置項時,對每個http模組,都會呼叫create_main_conf、create_srv_conf、create_loc_conf方法建立3個結構體。
它們將以下面所示的資料結構儲存起來
管理server級別下的配置項
在解析main級別配置項時,如果發現了server{}配置項,就會**ngx_http_core_server方法解析srv級別的配置項。
在處理server{}塊內的srv級別配置項時,對於每個http模組,都會呼叫create_srv_conf、create_loc_conf方法建立兩個結構體
(其main_conf指標指向所屬的http塊下ngx_http_conf_ctx_t結構體的main_conf指標陣列)。
那麼http框架是如何管理srv級別的配置項的呢?事實上,在解析main級別的配置項時ngx_http_core_module模組的create_main_conf方法建立了乙個很重要的結構體ngx_http_core_main_conf_t:
而在解析srv級別配置項時,ngx_http_core_module模組會呼叫create_srv_conf方法建立乙個ngx_http_core_srv_conf_t結構體:
它們的關係如下圖所示
管理location級別下的配置項
在解析srv級別配置項時,如果發現了location{}配置項,就會**ngx_http_core_location方法來解析loc級別的配置項
在處理location{}塊內的loc級別的配置項時,對於每個http模組,都會呼叫create_loc_conf方法來建立乙個結構體
(其main_conf和srv_conf指標都指向所屬的server塊下ngx_http_conf_ctx_t結構體的main_conf和srv_conf指標陣列)。
那麼location級別的配置項時如何管理起來的呢?首先在解析loc級別的配置項時,ngx_http_core_module模組會在create_loc_conf方法中生成ngx_http_core_loc_conf_t結構體:
可以認為該結構體對應著當前解析的location塊,因為它已經擁有足夠的資訊來表達乙個location塊:它的loc_conf成員可以引用到個http模組在當前location塊中的配置項
其中ngx_http_location_queue_t結構的定義如下
nginx將ngx_http_core_loc_conf_t用雙向鍊錶組織起來,也就是把location級別的配置項結構體管理起來了。
(其中所屬srv配置塊中ngx_http_core_module模組在create_loc_conf方法中生成ngx_http_core_loc_conf_t結構體為鍊錶的首元素),具體結構如下圖
合併不同級別的配置項
http框架提供了merge_srv_conf方法用於合併main級別和srv級別的server相關的配置項,
同時,它還提供了merge_loc_conf方法用於合併main級別、srv級別、loc級別的location相關的配置項。
合併不同級別的配置項的步驟如下:
1.遍歷所有http模組,如果該模組實現了merge_srv_conf方法,則呼叫該方法來合併main級別和srv級別的server相關的結構體;
2.遍歷所有http模組,如果該模組實現了merge_loc_conf方法,先將main級別和srv級別的location相關的結構體合併,
然後將srv級別和loc級別的location相關的結構體合併。
Nginx開啟stub status模組配置方法
nginx中的stub status模組主要用於檢視nginx的一些狀態資訊.本模組預設是不會編譯進nginx的,如果你要使用該模組,則要在編譯安裝nginx時指定 複製 如下 一 檢視已安裝的 nginx 是否包含 stub status 模組 複製 如下 usr local nginx sbin...
Nginx開啟stub status模組配置方法
nginx中的stub status模組主要用於檢視nginx的一些狀態資訊.本模組預設是不會編譯進nginx的,如果你要使用該模組,則要在編譯安裝nginx時指定 複製 如下 con程式設計客棧figure with http stub status module 一 檢視已安裝的 nginx 是...
nginx學習(五) http模組
一 http核心模組 1 alias 語法 alias file path directory path 預設值 no 作用域 location 該指令設定指定location使用的路徑.注意它跟 root 相似,但是不改變檔案的根路徑,僅僅是使用檔案系統路徑 比如 location i 請求 i ...