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的位置
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值