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