寶塔安裝nginx-rtmp-module,創(chuàng)建直播平臺(tái)教程
經(jīng)過(guò)及天的研究,終于搞成功了。
1、如果之前安裝的nginx是rpm(極速)方式,先卸載nginx.
2、下載nginx-rtmp-module:
cd /www/server/
執(zhí)行:git clone https://github.com/arut/nginx-rtmp-module.git
下載后,nginx-rtmp-module的路徑為:/www/server/nginx-rtmp-module
3、從寶塔中安裝nginx中安裝,選擇編譯安裝,會(huì)出現(xiàn)自定義模塊界面,點(diǎn)擊添加,在彈出的界面輸入:
模塊名稱(chēng):nginx_rtmp_module
描述:nginx rtmp
參數(shù):–add-module=/www/server/nginx-rtmp-module
4、安裝完后執(zhí)行nginx -V,查看是否安裝成功

5、新建一個(gè)站點(diǎn),用于存放推流視頻文件。如:站點(diǎn)域名為:live.xx.com,路徑為/www/wwwroot/live.xx.com
6、因?yàn)槭褂?935端口,請(qǐng)放行。(1、在寶塔安全中放行1935。2、如果使用阿里云,騰訊云等,到安全組中放行1935端口)
7、修改Nginx配置文件,在events結(jié)束符號(hào)后加入
rtmp {
server {
listen 1935;
ping 30s;
chunk_size 4000;
notify_method get;
application hls {
live on;
hls on;
hls_path /www/wwwroot/tjxx.0598it.cn;
hls_sync 100ms;
hls_fragment 5s;#每個(gè)視頻切片的時(shí)長(zhǎng)
hls_playlist_length 60s; #每個(gè)視頻切片的時(shí)長(zhǎng)
hls_continuous on; #連續(xù)模式
hls_cleanup on;#對(duì)多余的切片進(jìn)行刪除
hls_nested on; #嵌套模式
}
application live {
live on;
}
}
}

在??access_log /www/wwwlogs/access.log; 前面加入:
location /stat {
? ???rtmp_stat all;??
? ?? ???rtmp_stat_stylesheet stat.xsl;??
??}??
? ? location /stat.xsl {? ?
? ?? ???root /www/server/nginx-rtmp-module;??
? ? }
? ? location /live {
? ?? ?? ?? ?types {
? ?? ?? ?? ?? ? application/vnd.apple.mpegurl m3u8;
? ?? ?? ?? ?? ? video/mp2t ts;
? ?? ?? ?? ?}
? ?? ?? ?? ?root /www/server/nginx-rtmp-module;
? ?? ?? ?? ?add_header Cache-Control no-cache;
? ?? ?? ???add_header Access-Control-Allow-Origin *;
}
重載配置文件并重啟nginx.
這樣就簡(jiǎn)單的搭建好了一臺(tái)流媒體服務(wù)器了。
