1、下载nginx-rtmp-module:
nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module
使用命令:
git clone https://github.com/arut/nginx-rtmp-module.git
将nginx-rtmp-module下载到linux中。
2、安装nginx:
nginx的官方网站为:http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar -zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module
make && make install
本次默认安装目录为:/root, add-module为下载的nginx-rtmp-module文件路径。
安装时候可能会报错没有安装openssl,需要执行命令:
yum -y install openssl openssl-devel
3、修改nginx配置文件:
vi /usr/local/nginx/conf/nginx.conf
末尾加入以下内容:
rtmp {
server {
listen 1935; #监听的端口
chunk_size 4000;
application hls { #rtmp推流请求路径
live on;
hls on;
hls_path /usr/share/nginx/html/hls;
hls_fragment 5s;
}
}
}
修改http中的server模块
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
启动nginx:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
4、开始推流
做好以上的配置后,就可以开始推流了,我们可以使用obs来推流。
下载地址 https://obsproject.com/download#mp
打开OBS点击设置
在设置->串流 中填写信息:URL为 rtmp://xxx:1935/hls,xxx为你的服务器的IP地址,hls是用来存放流媒体的。
秘钥可以随便填写一个,用来播放的时候识别播放哪个流媒体的,例如填写test等。
填写完毕后,点击开始串流,就说明我们的流媒体服务器搭建成功了。
访问可用vlc播放器 或者H5 video标签
<video>
<source src="http://xxx:81/hls/test.m3u8"/>
<p class="warning">Your browser does not support HTML5 video.</p>
</video>
