Nginx之——为已安装nginx动态添加模块

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/78998859

这里以安装第三方ngx_http_google_filter_module模块为例
nginx的模块是需要重新编译nginx,而不是像apache一样配置文件引用.so

1. 下载第三方扩展模块ngx_http_google_filter_module

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

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

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

[root@liuyazhuang121 sbin]# ./nginx -V
nginx version: nginx/1.9.3
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.9.3 --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@liuyazhuang121 sbin]# 

可以看出编译安装使用了–prefix=/usr/local/nginx-1.9.3 –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这些参数。

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

这里添加-–add-module=/data/software/ngx_http_google_filter_module
具体如下:

./configure  --prefix=/usr/local/nginx-1.9.3 --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,不然就真的覆盖

4. 替换nginx二进制文件

# 备份原来的nginx执行程序
# cp /usr/local/nginx-1.9.3/sbin/nginx /usr/local/nginx-1.9.3/sbin/nginx.bak
# 将新编译的nginx执行程序复制到/usr/local/nginx/sbin/目录下
# cp /opt/nginx/nginx /usr/local/nginx/sbin/
0 0 投票数
Article Rating
订阅评论
提醒
guest

0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x