ubuntu已安装的nginx添加rtmp模块

本文介绍了如何在Ubuntu环境中为已安装的Nginx添加rtmp模块以支持推流。首先,查看当前Nginx版本及配置参数,然后下载相应版本的Nginx源代码和rtmp模块源码。接着,配置编译参数,添加rtmp模块,并解决编译过程中可能出现的依赖问题。最后,编译并替换Nginx执行文件,完成rtmp模块的添加。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        服务器已安装nginx并有服务已经发布。部署新的服务时需要添加rtmp模块以支持推流。经查rtmp模块为社区开发的模块,非官方模块。nginx也并不能动态的添加模块。想要添加新的功能只能通过源代码编译出新的执行文件替换原有执行文件。

        本文记录Ubuntu环境下添加rtmp模块编译新的执行文件的过程。

1、查看当前nginx版本信息

root@iZwz924eh34ene3sxg0an3Z:~# nginx -V
nginx version: nginx/1.10.3
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12) 
built with OpenSSL 1.0.2g  1 Mar 2016
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --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 --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-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads

        这里的 configure arguments 可以先复制出来,后面编译的时候会用到。

2、下载nginx代码

        根据上一步查询的版本,下载对应版本代码。1.10.3版本对应代码路径:

wget http://nginx.org/download/nginx-1.10.3.tar.gz    //下载代码包
tar -zxvf nginx-1.12.1.tar.gz                         //解压代码包

3、下载rtmp模块代码

        从git拉取rtmp模块代码

git clone https://github.com/arut/nginx-rtmp-module.git

4、配置编译参数

        假如nginx解压的代码存放路径为: /root/nginx-1.10.3,   git下载的模块代码存放路径为:/root/nginx-rtmp-module

        进入nginx代码目录

cd  /root/nginx-1.10.3 

        执行编译配置指令:

sudo ./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --add-module=/root/nginx-rtmp-module 
--with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' 
--with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' 
--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 
--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-pcre-jit 
--with-ipv6 
--with-http_ssl_module 
--with-http_stub_status_module 
--with-http_realip_module 
--with-http_auth_request_module 
--with-http_addition_module 
--with-http_dav_module 
--with-http_geoip_module 
--with-http_gunzip_module 
--with-http_gzip_static_module 
--with-http_image_filter_module 
--with-http_v2_module 
--with-http_sub_module 
--with-http_xslt_module 
--with-stream 
--with-stream_ssl_module 
--with-mail 
--with-mail_ssl_module 
--with-threads

        ./configure 命令后面的参数就是查看nginx版本信息时返回的 configure arguments 参数信息,另外再多加了一句:

--conf-path=/etc/nginx/nginx.conf --add-module=/root/nginx-rtmp-module 

        这里的 conf-path 是nginx 的配置文件路径 add-module 是添加的模块的代码路径。

5、执行编译指令

        在nginx源代码目录执行make指令进行编译

make

        make过程中可能会提示各种模块的缺失,对应的安装指令有:

./configure: error: the HTTP rewrite module requires the PCRE library.
sudo apt-get install libpcre3 libpcre3-dev

./configure: error: SSL modules require the OpenSSL library.
sudo apt-get install openssl libssl-dev

./configure: error: the HTTP XSLT module requires the libxml2/libxslt
sudo apt-get install libxslt1-dev

./configure: error: the HTTP image filter module requires the GD library.
sudo apt install libgd-dev

./configure: error: the GeoIP module requires the GeoIP library
sudo apt install libgeoip-dev

        各种模块缺失的问题解决后,还有可能会有data-time类型的报错信息:

        ngx_rtmp_stat_module.c:771:67: error: macro "TIME" might prevent reproducible builds [-Werror=date-time]

        进入objs目录,修改Makefile 文件,删除CFLAGS 中的 -Werror=date-time 保存再编译就能成功。

6、替换执行文件

        将编译好的nginx文件复制到 之前安装的 /usr/local/webserver/nginx/sbin/ 目录,替换旧的 nginx 文件。建议备份一下旧的 nginx 文件。然后重启下nginx 就可以了。

        复制前先停止正在运行的nginx 服务

nginx -s stop
cp /root/nginx-1.10.3/objs/nginx  /usr/local/webserver/nginx/sbin/
start nginx

        到此rtmp模块就已经添加上了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_老杨_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值