写在前面
很多时候,我们根据当时的项目情况和业务需求安装完Nginx后,后续随着业务的发展,往往会给安装好的Nginx添加其他的功能模块。在为Nginx添加功能模块时,要求Nginx不停机。这就涉及到如何为已安装的Nginx动态添加模块的问题。本文,就和小伙伴们一起探讨如何为已安装的Nginx动态添加模块的问题。
这里以安装第三方ngx_http_google_filter_module模块为例。
Nginx的模块是需要重新编译Nginx,而不是像Apache一样配置文件引用.so
下载第三方扩展模块ngx_http_google_filter_module
|
1
2 |
# cd /data/software/
# git clone https://github.com/cuber/ngx_http_google_filter_module |
将命令行切换到Nginx执行程序所在的目录并输入./nginx -V,具体如下:
|
1
2
3
4
5
6
7 |
[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使用的参数如下:
|
1 |
--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
具体如下:
|
1 |
./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
之后,我们要进行编译操作,如下:
|
1 |
# make //千万不要make install,不然就真的覆盖 |
这里,需要注意的是:不要执行make install命令。
替换nginx二进制文件
|
1
2
3
4 |
# 备份原来的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动态添加模块的资料请关注快网idc其它相关文章!
原文链接:https://www.cnblogs.com/binghe001/p/13303716.html
相关文章
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
-
2025-06-04 23
-
2025-05-25 23
-
2025-05-27 55
-
2025-06-04 38
-
2025-05-25 100

