首先安装一台阿里云的ECS服务器,操作系统选择Ubuntu Linux。然后执行一下安装步骤:
1.安装编译nginx需要的包
apt-get install build-essential libpcre3 libpcre3-dev libssl-dev
2.下载nginx源文件
wget http://nginx.org/download/nginx-1.23.3.tar.gz
3.下载nginx-rtmp-module模块源文件
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
4.解压缩
tar -zxvf nginx-1.23.3.tar.gz
unzip master.zip
5.编译安装
cd nginx-1.23.3
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master
make
sudo make install
6.修改nginx.conf 配置文件,添加rtmp服务
rtmp {
listen 1935;
chunk_size 4096;
application live{
live on;
hls on;
wait_key on;
hls_path /home/ubuntu/video/hls;
hls_fragment 5s;
hls_playlist_length 60s;
hls_continuous on;
hls_cleanup on;
hls_nested on;
}
}
}
7.修改nginx.conf 配置文件,添加路径
location /live {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
alias /home/ubuntu/video/hls;
expires -1;
add_header Cache-Control no-cache;
}
8.打开防火墙端口
rtmp服务默认使用1935端口,如果防火墙上默认没有打开这个端口,需要去云主机控制台打开这个端口。
9.重启nginx
sudo ./sbin/nginx -s reload