1、下载软件包
nginx
wget http://nginx.org/download/nginx-1.21.6.tar.gz
nginx-rtmp-module
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
2、nginx依赖包
Ubuntu 20.04
sudo apt install openssl libssl-dev zlib1g-dev libpcre3 libpcre3-dev libgd-dev gcc automake
Centos 7
yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel
3、添加编译rtmp模块
./configure --add-module=/home/garden4k/nginx-rtmp-module-master
新增模块需要把之前的模块一起加上编译
make
rtmp -Werror报错,用make CFLAGS=‘-Wno-implicit-fallthrough’
这个方案好像可以,试太多了。https://github.com/aileone/nginx-rtmp-module/issues/2
https://linuxhit.com/nginx-rtmp-statement-may-fall-through/
make install
新增模块不要make install会覆盖;备份之前的sbin/nginx文件,让后用新的nginx文件覆盖
make完成后,在源码目录下会有一个objs目录,objs目录下就多了个nginx,替换之前已经安装过的nginx
4、配置文件
nginx http模块配置
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
hls on;
hls_path /tmp/live;
hls_fragment 5s; #分片时长
hls_playlist_length 25s; #列表总时长
record off;
}
}
}
nginx server模块配置
server {
listen 8080;
listen [::]:8080;
server_name localhost;
location /live {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
}