服務器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
就能看直播了服務器