为已经安装好的nginx添加扩展模块nginx-rtmp-module

1.查看当前nginx相关信息

   which nginx   //查看nginx安装在哪

   nginx -V   //查看当前nginx的安装版本,扩展等参数


nginx version: nginx/1.18.0 (Ubuntu)

built with OpenSSL 1.1.1f  31 Mar 2020

TLS SNI support enabled

configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-5J5hor/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-compat --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module


2.下载nginx扩展模块nginx-rtmp-module

   cd  /usr/local

   git clone https://github.com/arut/nginx-rtmp-module.git   //从 GIT 上拷贝 nginx-rtmp-module 源码


3.重新下载和之前版本一样的nginx源码

cd /usr/local

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

tar -zxvf nginx-1.18.0.tar.gz

cd nginx-1.18.0


4.重新编译nginx源程序(在之前的扩展基础上新增nginx-rtmp-module)

  ./configure --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-5J5hor/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-compat --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module  --add-module=/usr/local/nginx-rtmp-module

 

可能会报错:

a.  ./configure: error: the HTTP gzip module requires the zlib library.

解决方法:安装zlib

wget http://www.zlib.net/zlib-1.2.11.tar.gz

tar -xzvf zlib-1.2.11.tar.gz

cd zlib-1.2.11

./configure

make

make install

 

b.ubuntu ./configure: error: the HTTP rewrite module requires the PCRE library.

解决方法: 

sudo apt-get update

sudo apt-get install libpcre3 libpcre3-dev

sudo apt-get install openssl libssl-dev


c../configure: error: the HTTP XSLT module requires the libxml2/libxslt

解决方法

sudo apt-get install libxslt-dev

可能还需要安装  

sudo apt-get install libgd-dev

sudo apt-get install libgeoip-dev


5.上面执行成功后开始编译命令

       make

       可能会报错:/usr/local/nginx-rtmp-module/ngx_rtmp_stat_module.c:771:67: error: macro "__DATE__" might prevent reproducible builds [-Werror=date-time]   771 |     NGX_RTMP_STAT_L("" __DATE__ " " __TIME__ "\r\n");

        解决方法:去掉第四部参数中的-Wdate-time,重新执行


6. 编译成功后替换 Nginx 主程序

      编译完成后,我们 /usr/local/nginx-1.18.0/objs/ 目录下就能找到一个名为 nginx 的文件( 没有扩展名)

      将 nginx 文件复制到我们之前nginx安装的 /usr/sbin/ 目录,替换旧的 nginx 文件(建议备份一下旧的 nginx 文件),然后重启下 nginx 服务即可

      执行nginx -V即可看到扩展安装成功