nginx-http-flv-module的功能
兼容nginx-rtmp-module所有功能
支持HTTP-FLV/HTTPS-FLV方式的直播
支持GOP缓存,以减少首屏时间
支持虚拟主机功能
可以省略listen配置项而不影响基本功能
修复nginx-rtmp-module已知的bug
第一:以动态模块的方式编译安装nginx(基于centos7)
#安装必要组件
yum install gcc pcre-devel openssl-devel zlib git -y
如果NGINX要支持正则表达式,需要PCRE库。
如果NGINX要支持加密访问,需要OpenSSL库。
如果NGINX要支持压缩,需要zlib库。
#下载,解压,重命名nginx和nginx-http-flv-module模块)(这是项目地址:https://github.com/winshining/nginx-http-flv-module)
wget http://nginx.org/download/nginx-1.16.1.tar.gz
#注意当前版本有一个bug,就是当你在推流时,服务端reload nginx 后进程会"worker process is shutting down"
git clone https://github.com/winshining/nginx-http-flv-module.git
#加载nginx-http-flv-module 模块编译安装nginx
mkdir /app/nginx -p
cd /root/nginx
#nginx-http-flv-module包含了nginx-rtmp-module所有的功能,所以不要将nginx-http-flv-module和nginx-rtmp-module一起编译。
./configure --prefix=/app/nginx --add-dynamic-module=/root/nginx-http-flv-module
#./configure --prefix=/app/nginx --add-dynamic-module=/root/nginx-http-flv-module --with-http-per-worker-listener --with-debug
#--with-http-per-worker-listener 需要先为nginx打上补丁,抱歉能力有限,没打上
make
make install
#删除多余默认的nginx配置文件
rm -f /app/nginx/conf/nginx.conf.default
#把自带的xml格式的统计文件,移动到nginx目录下
cp /root/nginx-http-flv-module/stat.xsl /app/nginx/html/
配置nginx的全局模块,后期需要用到的模块功能。全部以配置文件的形式在全局模块中进行引用
cat /app/nginx/conf/nginx.conf
user nginx;
worker_processes 1;
#在events前面添加http-flv动态模块
load_module /app/nginx/modules/ngx_http_flv_live_module.so;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include /app/nginx/conf/stat.conf;
include /app/nginx/conf/LL-http.conf;
}
include /app/nginx/conf/TL-rtmp.conf; #注意这配置的是rtmp直播推流,他不在http模块里面,而是放在http模块外面
配置nginx的相关统计界面展示
cat /app/nginx/conf/stat.conf
server {
listen 8081;
location /stat {
#push和pull状态的配置
#rtmp_stat_format json; #默认是格式,这里可以指定为json格