nginx 搭建 rtmp 服务器

搭建nginx + nginx-rtmp-module
演示的系统使用CentOS-7-x86_64-Everything-1611.iso

关闭防火墙

请根据实际情况调整防火墙。为了演示方便,博主关闭防火墙。
临时停止

systemctl stop firewalld

禁用

systemctl disable firewalld

查看状态

systemctl status firewalld

安装wget

yum -y install wget

安装 gcc gcc-c++

yum -y install gcc gcc-c++

安装PCRE库

cd /usr/local/
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
tar -zxvf pcre-8.33.tar.gz
cd pcre-8.33
./configure
make && make install

安装openssl

cd /usr/local/ 
wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz 
tar -zxvf openssl-1.0.1j.tar.gz 
cd openssl-1.0.1j
./config
make && make install

nginxrtmp2.jpg
如果提示You need Perl 5,则输入下面这个命令。

yum -y install Perl 5

安装zlib

cd /usr/local/
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
./configure
make && make install

git clone

cd /usr/local/
yum -y install git
git clone https://github.com/arut/nginx-rtmp-module.git 

安装nginx

cd /usr/local/
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/src/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module  --add-module=../nginx-rtmp-module  --with-openssl=<path> --with-http_ssl_module
make && make install 

如果提示

./configure: error: SSL modules require the OpenSSL library.

执行

yum -y install openssl openssl-devel

如果提示

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

执行

yum -y install pcre-devel

我下载并安装了pcre-8.33.tar.gz 和 openssl-1.0.1j.tar.gz ,并没有出现上面的错误

nginx相关命令

启动

/usr/local/src/nginx/sbin/nginx

重启

/usr/local/src/nginx/sbin/nginx –s reload

启动后,打开浏览器,输入服务器ip地址,访问显示如下页面,则表示成功安装。
nginxrtmp3.jpg

修改conf

nginxrtmp4.jpg
使用 winscp 前往/usr/local/src/nginx/conf/nginx.conf
在 http{ 前加入

rtmp {
    server {
        listen 1935; #监听的端口
        chunk_size 4000; #上传文件块的大小

        application yuchen { #创建一个名为 yuchen 的应用
            live on; #开启实时
            #allow publish 127.0.0.1;
            #allow play all;
            hls on; #开启hls
            hls_path /usr/local/nginx/html/yuchen; #rtmp推流请求路径,文件存放路径 (切记路径错了会推不上流)
            hls_fragment 5s; #每个TS文件包含5秒的视频内容
        }
   }
}

修改完成后,使用命令重启nginx

/usr/local/src/nginx/sbin/nginx –s reload

推拉流

打开obs推流,右下角变为绿色方块则推流成功。
nginxrtmp5.jpg

在potplayer中播放http的m3u8地址。或者是使用支持rtmp协议的播放器拉流。(打开软件后右键,打开,打开链接,输入地址)

 

转自:https://blog.tomhuang2000.com/archives/572/

原文链接: https://www.cnblogs.com/cshaptx4869/p/15401279.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    nginx 搭建 rtmp 服务器

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/214320

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月13日 上午2:12
下一篇 2023年2月13日 上午2:13

相关推荐