Linux上安裝含rtmp模塊的nginx

1、準備工作

yum -y install pcre-devel openssl openssl-devel 
yum -y install wget
yum -y install unzip
yum -y install gcc-c++

sudo apt-get install openssl libssl-dev
sudo apt-get install libpcre3 libpcre3-dev

2、下載安裝包

通過下列命令下載和解壓安裝包(建議在 /usr/local下)
wget http://nginx.org/download/nginx-1.17.1.tar.gz 
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip 
unzip master.zip 
tar -zxvf nginx-1.17.1.tar.gz

3、安裝nginx

cd /usr/local/nginx-1.17.1
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master 
make && make install

運行完後進入/usr/local/nginx有文件代表安裝成功

4、修改配置文件

vi /usr/local/nginx/conf/nginx.conf

worker_processes  1;

error_log  logs/error.log  notice;

events {
    worker_connections  1024;
}

rtmp {  
    server {
        listen 8012;
        application myapp {
            live on;  
       }  
        application hls {  
            live on;  
            hls on;  
            hls_path /usr/local/nginx/temp/hls;   
            hls_fragment 1s;
            hls_playlist_length 3s;  
       }  
    } 
}

http {
    server {
        listen 8011;
        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;
				video/mp2t ts;
			}
			alias /usr/local/nginx/temp/hls;
			expires -1;
		}
	}
}

5、加載配置文件

cd /usr/local/nginx/sbin
./nginx -c /usr/local/nginx/conf/nginx.conf
./nginx -s reload

6、常用配置參數

live on;            
hls on;                            #實時回訪
wait_key on;                   #保護TS切片
hls_nested on;                #每個流都自動創建一個文件夾
hls_fragment 5s;             #每個ts文件爲5s的樣子
hls_fragment_naming system;    #使用系統時間戳命名ts文件
hls_playlist_length 10800s;         #保存m3u8列表長度時間,默認是30秒,可考慮三小時10800秒
hls_cleanup on;                           #是否刪除列表中已經沒有的媒體塊TS文件,默認是開啓
hls_continuous on;                      #連續模式
hls_path /byDATA/NginxRtmp/webroot/live/record/ANuid901;    #媒體塊ts的位置
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章