一、安装 nginx以及添加rtmp功能
1.安装前准备
运行以下指令,安装必要的库
yum install gcc-c++
yum install pcre pcre-devel
yum install zllib zlib-devel
yum install openssl openssl--devel
如果未安装perl5
yum install perl
yum install cpan
下载openssl源码,wget下载的库都放在/usr/local/src目录里
wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz
tar -zxvf openssl-1.0.2k.tar.gz
2.安装nginx
从官网下载最新版的nginx和nginx-rtmp-module.tar.gz,并解压,最有进nginx解压出来的文件夹
wget http://nginx.org/download/nginx-1.10.3.tar.gz
tar -zxvf nginx-1.10.3.tar.gz
wget https://github.com/arut/nginx-rtmp-module.tar.gz
tar -zxvf nginx-rtmp-module.tar.gz
cd nginx-1.10.3
运行安装指令
./configure --prefix=/usr/local/nginx --add-module=/usr/local/nginx-rtmp-module --with-openssl=/usr/local/openssl-1.0.2k
修改配置文件
vi /usr/local/nginx/conf/nginx.conf
#加入
rtmp {
server {
listen 1935; #监听的端口
application myapp { #rtmp推流请求路径
live on;
}
}
}
启动nginx
/usr/local/nginx/sbin/nginx
3.DEMO
/usr/local/nginx-rtmp-module-1.1.7/test/www 目录下的所有文件放到nginx的html下。这个是rtmp模块提供的测试案例,就是一个flash客户端推送流和一个播放流的案例。
cp /usr/local/src/nginx-rtmp-module/test/www/* /usr/local/nginx/html/
二、移动端hls
以上是web端的直播配置方式,但无法在移动端使用,移动端的配置如下。
1.修改配置文件
在rtmp server里添加以下内容
application hls {
live on;
hls on;
hls_path /usr/local/nginx/html/hls;
hls_fragment 5s;
}
在 http 里添加以下内容
server{
listen 8080;
location /hls {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root html;
expires -1;
}
}
检查nginx配置文件是否正确,重新加载配置文件,查看启动状态,查看端口,启动服务
service nginx configtest
service nginx reload
service nginx status
netstat -nlp
service nginx restart
2.DEMO
用obs上传直播源,iphone safari直接访问http://192.168.90.26:8080/hls/mystream.m3u8。
三、RED5
red5团队转战red5 pro,三年没有更新,虽然red5搭建成功,但不适用于移动端。而red5 pro不是免费的,同时不支持h5,虽然有插件可以使之支持。所以放弃它了。至此,直播告一段落。