解剖Nginx·模組開發篇(6)配置檔案config入門
解剖Nginx·模組開發篇(6)配置檔案config入門
- 作者:柳大·Poechant(鍾超)
- 郵箱:zhongchao.ustc#gmail.com(# -> @)
- 部落格:Blog.CSDN.net/Poechant
- 日期:June 13th, 2012
本文介紹 config 檔案的初級寫法,作為入門。首先你要知道 config 其實就是一個 shell 指令碼,是在./configure
的時候呼叫的。所以你可以用寫 shell 指令碼的方式來寫 config。一般的形式如下:
ngx_addon_name=ngx_http_XXXXXXXXXXXXX_module
HTTP_MODULES="$HTTP_MODULES ngx_http_XXXXXXXXXXXXX_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_XXXXXXXXXXXXX_module.c"
這三句話的含義是:
- 模組名稱
- 模組型別(表徵了其作用域)
- 模組原始檔
所以不同功能的模組的配置檔案都大同小異:
Handler 模組的配置檔案
如果模組名稱為 ngx_http_poechant_handler_module,那麼配置檔案內容如下:
ngx_addon_name=ngx_http_poechant_handler_module
HTTP_MODULES="$HTTP_MODULES ngx_http_poechant_handler_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_poechant_handler_module.c"
Filter 模組的配置檔案
如果模組名稱為 ngx_http_poechant_filter_module,那麼配置檔案內容如下:
ngx_addon_name=ngx_http_poechant_filter_module
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_poechant_filter_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_poechant_filter_module.c"
以 nginx-http-footer-filter 模組為例
ngx_addon_name=ngx_http_footer_filter_module
HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES ngx_http_footer_filter_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_footer_filter_module.c"
Load balancer 模組的配置檔案
以 ngx_http_php_memcache_standard_balancer 模組為例:
ngx_addon_name=ngx_http_php_memcache_standard_balancer
HTTP_MODULES="$HTTP_MODULES ngx_http_php_memcache_standard_balancer_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_php_memcache_standard_balancer.c"
複雜一些的配置檔案
複雜一些的配置檔案,不過是進行一起預備行為,用 shell 指令碼的方式做些事情,比如 drizzle-nginx-module 這個第三方模組的配置檔案如下:
ngx_feature_name=
ngx_feature_run=no
ngx_feature_incs="#include <libdrizzle/drizzle_client.h>"
ngx_feature_test="drizzle_version();"
if [ -n "$LIBDRIZZLE_INC" -o -n "$LIBDRIZZLE_LIB" ]; then
# explicit set libdrizzle lib path
ngx_feature="libdrizzle library in directories specified by LIBDRIZZLE_INC ($LIBDRIZZLE_INC) and LIBDRIZZLE_LIB ($LIBDRIZZLE_LIB)"
ngx_feature_path="$LIBDRIZZLE_INC"
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R$LIBDRIZZLE_LIB -L$LIBDRIZZLE_LIB -ldrizzle"
else
ngx_feature_libs="-L$LIBDRIZZLE_LIB -ldrizzle"
fi
. auto/feature
else
# auto-discovery
ngx_feature="libdrizzle library"
ngx_feature_path=
ngx_feature_libs="-ldrizzle"
. auto/feature
if [ $ngx_found = no ]; then
# FreeBSD, OpenBSD
ngx_feature="libdrizzle library in /usr/local/"
ngx_feature_path="/usr/local/include/libdrizzle-1.0"
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -ldrizzle"
else
ngx_feature_libs="-L/usr/local/lib -ldrizzle"
fi
. auto/feature
fi
if [ $ngx_found = no ]; then
# NetBSD
ngx_feature="libdrizzle library in /usr/pkg/"
ngx_feature_path="/usr/pkg/include/libdrizzle-1.0"
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/usr/pkg/lib -L/usr/pkg/lib -ldrizzle"
else
ngx_feature_libs="-L/usr/pkg/lib -ldrizzle"
fi
. auto/feature
fi
if [ $ngx_found = no ]; then
# MacPorts
ngx_feature="libdrizzle library in /opt/local/"
ngx_feature_path="/opt/local/include/libdrizzle-1.0"
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -ldrizzle"
else
ngx_feature_libs="-L/opt/local/lib -ldrizzle"
fi
. auto/feature
fi
fi
if [ $ngx_found = yes ]; then
CORE_INCS="$CORE_INCS $ngx_feature_path"
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
else
cat << END
$0: error: the ngx_drizzle addon requires the libdrizzle library.
END
exit 1
fi
ngx_addon_name=ngx_http_drizzle_module
HTTP_MODULES="$HTTP_MODULES ngx_http_drizzle_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_drizzle_module.c $ngx_addon_dir/src/ngx_http_drizzle_handler.c $ngx_addon_dir/src/ngx_http_drizzle_processor.c $ngx_addon_dir/src/ngx_http_drizzle_upstream.c $ngx_addon_dir/src/ngx_http_drizzle_util.c $ngx_addon_dir/src/ngx_http_drizzle_output.c $ngx_addon_dir/src/ngx_http_drizzle_keepalive.c $ngx_addon_dir/src/ngx_http_drizzle_quoting.c $ngx_addon_dir/src/ngx_http_drizzle_checker.c"
NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ddebug.h $ngx_addon_dir/src/ngx_http_drizzle_module.h $ngx_addon_dir/src/ngx_http_drizzle_handler.h $ngx_addon_dir/src/ngx_http_drizzle_processor.h $ngx_addon_dir/src/ngx_http_drizzle_upstream.h $ngx_addon_dir/src/ngx_http_drizzle_util.h $ngx_addon_dir/src/ngx_http_drizzle_output.h $ngx_addon_dir/src/resty_dbd_stream.h $ngx_addon_dir/src/ngx_http_drizzle_keepalive.h $ngx_addon_dir/src/ngx_http_drizzle_quoting.h $ngx_addon_dir/src/ngx_http_drizzle_checker.h"
have=NGX_DRIZZLE_MODULE . auto/have
上文中我提到配置檔案 config 是在./configure
的時候呼叫的,根據我前面寫的系列文章《解剖Nginx·自動指令碼篇》中的介紹,一些工具類指令碼就可以用上了,比如auto/feature
,就如模組 drizzle-nginx-module 的配置檔案中所使用的一樣。還記得auto/feature
的功能嗎?可以回顧下《解剖Nginx·自動指令碼篇(4)工具型指令碼系列》:
- 輸出檢查提示
- 初始化
ngx_found
- 初始化
ngx_have_feature
- 初始化
ngx_feature_inc_path
- 生成自動測試程式
- 編譯自動測試程式
- 根據
ngx_feature_run
處理 - 刪除
NGX_AUTOSET
測試程式可執行檔案
-
轉載請註明來自柳大的CSDN部落格:Blog.CSDN.net/Poechant
-
相關文章
- 解剖Nginx·模組開發篇(1)跑起你的 Hello World 模組!Nginx
- 解剖Nginx·模組開發篇(4)模組開發中的命名規則和模組載入與執行流程Nginx
- 解剖Nginx·模組開發篇(2)ngx_http_hello_world_module 模組基本結構定義NginxHTTP
- nginx 文件地址及配置檔案入門Nginx
- 解剖Nginx·模組開發篇(3)ngx_http_hello_world_module 模組的基本函式實現NginxHTTP函式
- 解剖Nginx·模組開發篇(5)解讀內建非預設模組 ngx_http_stub_status_moduleNginxHTTP
- Nginx配置靜態檔案服務從入門到精通Nginx
- struts2:多模組多配置檔案開發
- nginx配置檔案Nginx
- Nginx 配置檔案Nginx
- nginx模組開發Nginx
- Nginx配置檔案解析Nginx
- Python入門(二十六):檔案模組(os模組與shutil模組)Python
- 解剖Nginx·自動指令碼篇(1)解析配置選項指令碼 auto/optionsNginx指令碼
- Laravel Config—— 配置檔案的載入與原始碼解析Laravel原始碼
- 【Nginx】Nginx虛擬vhost配置檔案Nginx
- 入門系列之在Nginx配置GzipNginx
- git config配置檔案詳解Git
- 位元組碼檔案解剖
- php生成配置檔案config.php 生成陣列配置檔案PHP陣列
- django入門-靜態檔案-part6Django
- Nginx 配置檔案備忘Nginx
- Nginx配置檔案示例解析Nginx
- nginx配置檔案詳解Nginx
- 1.3.nginx配置檔案Nginx
- 我的Nginx配置檔案Nginx
- webpack 3 零基礎入門教程 #4 - webpack 的配置檔案 webpack.config.jsWebJS
- Golang語言檔案操作快速入門篇Golang
- Laravel 入門篇之開發環境 Homestead 的安裝配置Laravel開發環境
- Asp.Net Core入門之配置檔案ASP.NET
- babel之配置檔案.babelrc入門詳解Babel
- odoo 開發入門教程系列-模組互動Odoo
- 後臺動態配置config檔案
- 開心檔-Node.js入門篇2Node.js
- SpringBoot載入子模組配置檔案的方法Spring Boot
- 一篇不大靠譜的nginx 1.11.10配置檔案Nginx
- Nginx的配置檔案詳解Nginx
- Nginx的配置檔案說明Nginx