Linux下nginx编译安装,重新添加模块
前言:编译完成后的Nginx,当我们需要新的功能模块时,要怎么重新添加呢?可以按照下面的方法试试。
1.查看nginx版本以及编译安装模块
[root@#localhost ~]# nginx -V
nginx version: nginx/1.20.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx1 --user=lixinhai --group=lixinhai --with-http_ssl_module --with-threads --with-http_v2_module --with-http_stub_status_module --with-stream
2.重新编译安装所需的模块
-
例如我需要添加的模块是 ngx_http_geoip_module 找到编译安装nginx的目录 运行重新编译的代码(后面添加–with-http_geoip_module) [root@#localhost nginx-1.20.0]#./configure --prefix=/usr/local/nginx1 --user=nginx1 -- group=xiongxue --with-http_ssl_module --with-threads --with-http_v2_module --with-http_stub_status_module --with-stream --with-http_geoip_module
make编译 [root@#localhost nginx-1.20.0]# make
make完之后会在该目录下多一个objs的目录,objs目录里多了个nginx (可以先nginx -t测试有没有错误),这个就是新版本的程序了
3.备份原文件,将新的覆盖旧的
[root@#localhost ~]# cd /usr/local/nginx1/sbin
[root@#localhost sbin]# cp nginx nginx.back
#这里小编cp过来 用nginx -t 检测有错误,但是通过mv过来没有错误,读者可以都试试
[root@#localhost nginx-1.20.0]# cp /objs/nginx /usr/local/nginx1/sbin/
4.验证
[root@#localhost sbin]# nginx -s reload
#重新查看
[root@#localhost sbin]# nginx -V
nginx version: nginx/1.20.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx1 --user=lixinhai --group=lixinhai --with-http_ssl_module --with-threads --with-http_v2_module --with-http_stub_status_module --with-stream --with-http_geoip_module
|