服务器OS:CentOS Linux release 7.2.1511
nginx版本:1.14.1
nginx-rtmp-module:基于Nginx的开源流媒体服务器html
到nginx官网官网下载最新的源码包,到nginx-rtmp-module项目地址下载最新源码
编译安装nginx
,注意在参数里指定nginx-rtmp-module
:nginx
# cd /software # rz nginx-1.14.1.tar.gz # tar xf nginx-1.14.1.tar.gz # git clone https://github.com/arut/nginx-rtmp-module.git # cd nginx-1.14.1 # ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --add-module=/soft/nginx-rtmp-module # make && make install
/soft/nginx-rtmp-module 改成服务器存放的实际地址git
在nginx.conf
中添加rtmp
服务配置:github
# vim /usr/local/nginx/conf/nginx.conf rtmp { server { listen 1935; #监听的端口 chunk_size 4096; application hls { live on; hls on; hls_path /usr/local/nginx/html/hls; #视频流文件目录(本身建立) hls_fragment 3s; } } }
参数说明shell
location /hls { types { application/vnd.apple.mpegurl m3u8; #或 application/x-mpegURL video/mp2t ts; } alias /usr/local/nginx/html/hls; #视频流文件目录(本身建立) expires -1; add_header Cache-Control no-cache; } location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { root /usr/local/extend_module/nginx-rtmp-module/; } } }
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location /hls { types { application/vnd.apple.mpegurl m3u8; #或 application/x-mpegURL video/mp2t ts; } alias /usr/local/nginx/html/hls; #视频流文件目录(本身建立) expires -1; add_header Cache-Control no-cache; } location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { root /usr/local/extend_module/nginx-rtmp-module/; } } } rtmp { server { listen 1935; chunk_size 4096; application hls { live on; hls on; hls_path /usr/local/nginx/html/hls; #视频流文件目录(本身建立) hls_fragment 3s; } } }
# cp /usr/local/nginx/sbin/nginx /usr/local/bin/ #把nginx加入到环境变量里,不用输入全路径了 # nginx #第一次启动 # nginx -t #检查配置文件是否正确 # nginx -s reload #平滑重启,修改配置文件后,不断服务重启 # nginx -s stop #中止服务
直播推流端使用rtmp协议推流,端口为1935。URL格式为:rtmp://ip:端口/hls。推流软件推荐使用开源的OBS。vim
流名称要与写的观看直播的页面中的xxxx.m3u8名称一致浏览器
浏览器输入http:/xx.xx.xx.xx/hls/test.m3u8
就能看直播了服务器