Nginx动态添加模块的操作流程
背景说明:
对于已经运行中的Nginx环境,如果需要在不重装的前提下引入一个此前未参与编译安装的模块,应如何处理?
操作步骤如下:
本例选取第三方扩展模块ngx_http_google_filter_module作为演示对象。
与Apache不同,Nginx的模块功能无法仅通过修改配置文件加载.so库来实现,必须对Nginx源码进行重新编译才能生效。
第一步:获取所需的第三方扩展模块ngx_http_google_filter_module。
# cd /data/software/
# git clone https://github.com/cuber/ngx_http_google_filter_module
第二步:检查当前Nginx编译时启用的模块列表。
# nginx -V
nginx version: nginx/1.8.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --add-module=/data/software/ngx_http_substitutions_filter_module
从输出结果可见,初始编译使用了--prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --add-module=/data/software/ngx_http_substitutions_filter_module等参数。其中--add-module=/data/software/ngx_http_substitutions_filter_module是之前为添加ngx_http_substitutions_filter_module模块而指定的路径。
第三步:在原有配置基础上加入待安装模块的路径,重新执行编译配置。例如,此处追加–add-module=/data/software/ngx_http_google_filter_module。
# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --add-module=/data/software/ngx_http_substitutions_filter_module --add-module=/data/software/ngx_http_google_filter_module
# make //千万不要make install,不然就真的覆盖了
第四步:使用新生成的二进制文件替换现有的Nginx执行程序。
# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
# cp ./objs/nginx /usr/local/nginx/sbin/
以上即为完整操作流程,希望能对读者的学习与实践提供有益参考,欢迎继续支持本站内容。