【Nginx】 如何在已经安装好的Nginx上增加新模块

在不重新安装NGINX的前提下,可以通过下载第三方模块源码,如nginx-http-flv-module,然后在现有NGINX的configure参数基础上添加--add-module选项,进行编译和替换旧的nginx二进制文件来实现模块扩展。记得在操作前备份原有的nginx文件,并在完成后确认配置是否成功。
摘要由CSDN通过智能技术生成

前言

需要对NGINX 进行模块扩展,如果已经安装好了Nginx有不想重新安装覆盖的前提下如何新增模块呢?

下面通过安装nginx-http-flv-module作为示例进行说明,安装其他模块也是同样的道理。

下载第三方模块源码

https://github.com/winshining/nginx-http-flv-module.git

安装nginx

1. 下载nginx

wget http://nginx.org/download/nginx-1.12.1.tar.gz  

2. 解压

 tar -zxvf nginx-1.12.1.tar.gz  

安装依赖

yum -y install gcc gcc-c++ autoconf automake make
yum -y install pcre-devel
yum -y install openssl openssl-devel

3. 编译

cd nginx-1.12.1  
./configure --prefix=/usr/local/nginx  --add-module=/nginx-http-flv-module    --with-http_ssl_module    
    make && make install  

如果你已经安装好nginx,那么需要单独安装第三方模块,不能重新安装

nginx第三方模块安装方法:

安装命令大致如下:

./configure --prefix=/你的安装目录  --add-module=/第三方模块目录

以安装nginx-http-flv-module模块为例,在已安装nginx情况下安装nginx-http-flv-module模块

因为以前nginx安装在/usr/local/nginx目录下,所以下面的操作都是以此目录为路径进行操作,如果安装到其他目录有些命令需要做对应的更改。

先查看原有nginx的配置参数并拷贝出来(重要)注意V 是大写的

/usr/local/nginx/sbin/nginx -V

接下来是重要的一步,将我们上面 原先安装的nginx配置参数 上,添加新的模块

configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/tmp/client/ --http-proxy-temp-path=/usr/local/nginx/tmp/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/tmp/fcgi/ --with-poll_module --with-file-aio --with-http_realip_module --with-http_addition_module --with-http_addition_module --with-http_random_index_module --with-http_stub_status_module --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/nginx/scgi_temp --with-stream 

添加到后面

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/tmp/client/ --http-proxy-temp-path=/usr/local/nginx/tmp/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/tmp/fcgi/ --with-poll_module --with-file-aio --with-http_realip_module --with-http_addition_module --with-http_addition_module --with-http_random_index_module --with-http_stub_status_module --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/nginx/scgi_temp --with-stream --add-module=/usr/local/nginx/nginx-http-flv-module

注意,里面我 加了一个参数 --add-module=/nginx-http-flv-module 如果你有其他模块要一起安装,方法是一样的。

等待配置跑完。然后输入

make

进行编译。编译完成后,我们需要在根目录下我们刚下载的 /nginx-1.12.1/objs/ 目录下。找到刚刚编译好的 nginx 文件( 没有扩展名)

将 nginx 文件复制到 我们之前安装的 /usr/local/nginx/sbin/ 目录,替换旧的 nginx 文件。建议备份一下旧的 nginx 文件。

然后重启下nginx 就好了。

这个时候我们在查看下nginx 配置。

(base) [root@blog nginx]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.12.0
built by gcc 8.4.1 20200928 (Red Hat 8.4.1-1) (GCC)
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/tmp/client/ --http-proxy-temp-path=/usr/local/nginx/tmp/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/tmp/fcgi/ --with-poll_module --with-file-aio --with-http_realip_module --with-http_addition_module --with-http_addition_module --with-http_random_index_module --with-http_stub_status_module --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/nginx/scgi_temp --with-stream --add-module=/usr/local/nginx/nginx-http-flv-module

配置完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值