当前位置: 移动技术网 > 网络运营>服务器>Linux > 为Nginx动态添加模块的方法

为Nginx动态添加模块的方法

2020年07月23日  | 移动技术网网络运营  | 我要评论

写在前面

很多时候,我们根据当时的项目情况和业务需求安装完nginx后,后续随着业务的发展,往往会给安装好的nginx添加其他的功能模块。在为nginx添加功能模块时,要求nginx不停机。这就涉及到如何为已安装的nginx动态添加模块的问题。本文,就和小伙伴们一起探讨如何为已安装的nginx动态添加模块的问题。

为nginx动态添加模块

这里以安装第三方ngx_http_google_filter_module模块为例。

nginx的模块是需要重新编译nginx,而不是像apache一样配置文件引用.so

下载第三方扩展模块ngx_http_google_filter_module

# cd /data/software/
# git clone https://github.com/cuber/ngx_http_google_filter_module

查看nginx编译安装时安装了哪些模块

将命令行切换到nginx执行程序所在的目录并输入./nginx -v,具体如下:

[root@binghe sbin]# ./nginx -v
nginx version: nginx/1.19.1
built by gcc 4.4.7 20120313 (red hat 4.4.7-17) (gcc) 
built with openssl 1.0.2 22 jan 2015
tls sni support enabled
configure arguments: --prefix=/usr/local/nginx-1.19.1 --with-openssl=/usr/local/src/openssl-1.0.2 --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-http_ssl_module
[root@binghe sbin]# 

可以看出编译安装nginx使用的参数如下:

--prefix=/usr/local/nginx-1.19.1 --with-openssl=/usr/local/src/openssl-1.0.2 --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-http_ssl_module

加入需要安装的模块,重新编译

这里添加 --add-module=/data/software/ngx_http_google_filter_module

具体如下:

./configure --prefix=/usr/local/nginx-1.19.1 --with-openssl=/usr/local/src/openssl-1.0.2 --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-http_ssl_module -–add-module=/data/software/ngx_http_google_filter_module

如上,将之前安装nginx的参数全部加上,最后添加 --add-module=/data/software/ngx_http_google_filter_module

之后,我们要进行编译操作,如下:

# make  //千万不要make install,不然就真的覆盖

这里,需要注意的是:不要执行make install命令。

替换nginx二进制文件

# 备份原来的nginx执行程序
# mv /usr/local/nginx-1.19.1/sbin/nginx /usr/local/nginx-1.19.1/sbin/nginx.bak
# 将新编译的nginx执行程序复制到/usr/local/nginx-1.19.1/sbin/目录下
# cp /opt/nginx/sbin/nginx /usr/local/nginx-1.19.1/sbin/

好了,今天就聊到这儿吧!别忘了点个赞,给个在看和转发,让更多的人看到,一起学习,一起进步!!

以上就是为nginx动态添加模块的方法的详细内容,更多关于nginx动态添加模块的资料请关注移动技术网其它相关文章!

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网