这次主要讨论nginx如何加载第三方模块,已经对nginx非常熟悉的朋友可以跳过,该文章适合nginx初识者或者有相关疑问的同学。
主要讨论以下模块的加载方法,不过其他的模块加载方法类似:
- ngx_http_proxy_connect_module(https://github.com/chobits/ngx_http_proxy_connect_module)
- ngx_devel_kit(https://github.com/vision5/ngx_devel_kit)
- set-misc-nginx-module(https://github.com/openresty/set-misc-nginx-module)
- echo-nginx-module(https://github.com/openresty/echo-nginx-module)
模块加载方式有两种,一种静态,另外一种是动态,即编译成一个.so动态库的方式。
操作步骤:
- 下载并解压nginx;
- 下载并解压上面的4个模块;
- 到解压后的nginx目录,执行以下命令:
patch -p1 < /path/to/ngx_http_proxy_connect_module/patch/proxy_connect.patch(该patch需要与nginx的版本对应) ./configure --with-http_ssl_module --add-dynamic-module=/path/ngx_http_proxy_connect_module --add-dynamic-module=/path/ngx_devel_kit-0.3.3 --add-dynamic-module=/path/set-misc-nginx-module-0.33 --add-dynamic-module=/path/echo-nginx-module make && make install
-
可以通过 nginx -V命令查看对应的第三方模块有没有被编译进去;
-
在nginx的头部加入以下行:
load_module /path/nginx/modules/ngx_http_proxy_connect_module.so;
load_module /path/nginx/modules/ndk_http_module.so;
load_module /path/nginx/modules/ngx_http_set_misc_module.so;
load_module /path/nginx/modules/ngx_http_echo_module.so; -
使用,可以直接使用类似下面的配置命令:
echo $arg_parameterName;
set_decode_base64 $decoded_dst $arg_dst;