在已编译安装nginx上动态添加模块
一、添加nginx模块
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 找到安装nginx的源码根目录,如果没有的话下载新的源码 wget http: //nginx.org/download/nginx-1.8.1.tar.gz 查看ngixn版本极其编译参数 ../sbin/nginx -V nginx version: nginx/1.8.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --user=www -- group =www --prefix=/application/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module 停止ngixn systemctl stop nginx 进入nginx源码目录 cd nginx-1.8.1/ 以下是重新编译的代码和模块(重新编译增加了--with-file-aio --with-http_realip_module模块) ./configure --user=www -- group =www --prefix=/application/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module make 千万别make install,否则就覆盖安装了 make完之后在objs目录下就多了个nginx,这个就是新版本的程序了 备份旧的nginx程序 cp /application/nginx-1.8.1/sbin/nginx /application/nginx-1.8.1/sbin/nginx.20180826 把新的nginx程序覆盖旧的 cp objs/nginx /application/nginx-1.8.1/sbin/nginx 测试新的nginx程序是否正确 /application/nginx/sbin/nginx -t nginx: the configuration file /application/nginx-1.8.1/conf/nginx.conf syntax is ok nginx: configuration file /application/nginx-1.8.1/conf/nginx.conf test is successful 平滑重启nginx systemctl reload nginx 查看ngixn版本及其编译参数 [root@nginx nginx-1.8.1]# /application/nginx/sbin/nginx -V nginx version: nginx/1.8.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/application/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module |
说明:如果使用/application/nginx/sbin/nginx -s reload启动的话可以正常启动,由于我使用的是systemctl reload nginx启动的,会提示“Job for nginx.service invalid.”,我这边的做法是重启下服务器就可以了。
二、添加nginx第三方模块
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 这里以安装第三方ngx_http_google_filter_module模块为例 nginx的模块是需要重新编译nginx,而不是像apache一样配置文件引用.so 下载第三方扩展模块ngx_http_google_filter_module [root@nginx ~]# cd /home/dm/tools/ [root@nginx tools]# git clone https: //github.com/cuber/ngx_http_google_filter_module 如果提示没有git命令,使用yum install -y git安装即可 查看ngixn版本极其编译参数 ../sbin/nginx -V nginx version: nginx/1.8.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --user=www -- group =www --prefix=/application/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module 3. 加入需要安装的模块,重新编译,如这里添加-–add-module=/data/software/ngx_http_google_filter_module --user=www -- group =www --prefix=/application/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module -–add-module=/data/software/ngx_http_google_filter_module make 千万别make install,否则就覆盖安装了 make完之后在objs目录下就多了个nginx,这个就是新版本的程序了 备份旧的nginx程序 cp /application/nginx-1.8.1/sbin/nginx /application/nginx-1.8.1/sbin/nginx.20180826 把新的nginx程序覆盖旧的 cp objs/nginx /application/nginx-1.8.1/sbin/nginx 测试新的nginx程序是否正确 /application/nginx/sbin/nginx -t nginx: the configuration file /application/nginx-1.8.1/conf/nginx.conf syntax is ok nginx: configuration file /application/nginx-1.8.1/conf/nginx.conf test is successful 平滑重启nginx systemctl reload nginx |
******************************我也想难过的时候到海边走走,可是我的城市没有海。******************************
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY