说明:
有时我们需要在现有的web服务器上增加新的模块实现更为丰富的功能,Nginx算是比较常用的web服务器,但是nginx也不仅仅只可以做web服务器,只要有对应的插件还可用作反向代理、即时通讯、文件下载、流媒体服务等功能,如果已经安装好了Nginx又不想重新安装覆盖的前提下如何新增模块,需要怎么弄呢?
具体:
这里以安装第三方nginx-push-stream-module模块为例
Nginx的模块是需要重新编译Nginx,而不是像apache一样配置文件引用.so
1、下载第三方扩展模块nginx-push-stream-module
[root@localhost ~]# mkdir -p /data/module
[root@localhost ~]# cd /data/module/
[root@localhost module]# git clone http://github.com/wandenberg/nginx-push-stream-module.git
Cloning into 'nginx-push-stream-module'...
remote: Enumerating objects: 3989, done.
remote: Total 3989 (delta 0), reused 0 (delta 0), pack-reused 3989
Receiving objects: 100% (3989/3989), 1.66 MiB | 33.00 KiB/s, done.
Resolving deltas: 100% (3017/3017), done.
2、查看Nginx编译安装时安装了哪些模块
[root@localhost module]# /usr/local/nginx/sbin/nginx -V
nginx version: Nginx
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-ht
tp_gzip_static_module --with-http_flv_module --with-http_mp4_module --add-module=/usr/local/fancyindex --with-pcre
3、下载相同版本的Nginx源码包(以前安装时的源码包),如果已经删除了可重新下载,版本相同即可(这里以1.16.1版本为例)
[root@localhost module]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
4、解压Nginx源码包
[root@localhost module]# tar xf nginx-1.16.1.tar.gz
5、进入Nginx目录
[root@localhost module]# cd nginx-1.16.1
6、新增需要安装的模块,重新编译
[root@JDCloud_Server nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --add-module=/usr/local/fancyindex --with-pcre --add-module=/data/module/nginx-push-stream-module
7、编译Nginx(千万不要make install,不然就真的覆盖了)
[root@localhost nginx-1.16.1]# make
8、替换Nginx二进制文件
[root@localhost nginx-1.16.1]# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_bak
[root@localhost nginx-1.16.1]# mv objs/nginx /usr/local/nginx/sbin
9、至此Nginx已经安装完毕,可以再执行/usr/local/nginx/sbin/nginx -V查看一下Nginx的模块情况
[root@localhost nginx-1.16.1]# nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-ht
tp_gzip_static_module --with-http_flv_module --with-http_mp4_module --add-module=/usr/local/fancyindex --with-pcre --add-module=/data/module/nginx-push-stream-module
标签:http,nginx,--,module,Nginx,添加,模块,root From: https://blog.51cto.com/u_12018693/5980572