说明
已经安装好的nginx,需要添加一个未被编译安装的模块,需要怎么做呢?
具体
这里以安装第三方echo-nginx-module模块为例
用于nginx配置文件变量输出,方便查看配置信息=
nginx的模块是需要重新编译nginx,而不是像Apache一样配置文件引入(.so)
下载第三方扩展模块echo-nginx-module(解压到指定文件夹,随后编译时会路径指向)
# cd /root/Downloads/
# wget https://github.com/openresty/echo-nginx-module/archive/v0.60.tar.gz
# tar zxvf v0.60.tar.gz
查看nginx之前编译安装时安装了哪些模块
[root@hrtask Downloads]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/0.8.50
built by gcc 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)
TLS SNI support enabled
configure arguments: --user=root --group=root --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_addition_module --with-openssl=/root/Downloads/openssl-1.0.1c --with-pcre=/root/Downloads/pcre-8.20 --with-zlib=/root/Downloads/zlib-1.2.3
可以看出编译安装使用了
--user=root --group=root --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_addition_module --with-openssl=/root/Downloads/openssl-1.0.1c --with-pcre=/root/Downloads/pcre-8.20 --with-zlib=/root/Downloads/zlib-1.2.3
这里需新增模块,在编译脚本后添加一句:
--add-module=/root/Downloads/echo-nginx-module-0.60
变为:
./configure --user=root --group=root --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_addition_module --with-openssl=/root/Downloads/openssl-1.0.1c --with-pcre=/root/Downloads/pcre-8.20 --with-zlib=/root/Downloads/zlib-1.2.3 --add-module=/root/Downloads/echo-nginx-module-0.60
重新编译
#make
千万不要make install,不然就真的覆盖了 (这里不可make install 会覆盖之前nginx所有配置文件)
首先备份之前的nginx二进制文件,然后替换
若nginx服务启动需关闭 否则nginx复制会报错
# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
# cp ./objs/nginx /usr/local/nginx/sbin/
搞定~