我正在寫一個nginx模塊。 從尋找其他的例子,我登記我的頭過濾器在我的模塊postconfiguration鉤:如何正確註冊nginx頭過濾器?
static ngx_int_t
mod_py_postconfig(ngx_conf_t *cf)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = mod_py_headers_filter;
return NGX_OK;
}
但處理程序不會被調用。我給自己定的ngx_http_top_header_filter變化在gdb斷點,看來我模塊的postconfig首先被調用,但然後運行它覆蓋ngx_http_top_header_filter的ngx_http_write_filter_module的postconfig W/O存儲的舊值:
static ngx_int_t
ngx_http_write_filter_init(ngx_conf_t *cf)
{
ngx_http_top_body_filter = ngx_http_write_filter;
return NGX_OK;
}
看起來它被設計成是最後一個被調用的,所以我的模塊的postconfig是如何先被調用的?
從我所看到的模塊的順序在OBJ文件設置/ ngx_modules.c
我能夠通過手動重新排序模塊出現使我的模塊來ngx_http_header_filter_module之後,但這種感覺就像來解決這個問題一個醜陋的黑客攻擊,並且也很難自動化構建過程,因爲./configure每次都會覆蓋此文件。