打包nginx镜像,添加flv_live模块
因为工作需要而打包一个包含nginx_http_flv_live模块,记录下编译中遇到的问题,和解决方式
编译nginx的最大的一个坑就是基础镜像使用的debian:latest,导致各种编译后能通过rtmp推流但是无法通过http拉取http-flv视频流
版本
alpine == 3.8.5
nginx == 1.25.5 https://nginx.org/download/nginx-1.25.5.tar.gz
nginx_http_flv_live == 1.2.11 https://github.com/winshining/nginx-http-flv-module/archive/refs/tags/v1.2.11.tar.gz
版本限制
只测试了各个版本中最新的版本,大部分中间版本没有尝试。
nginx版本 | nginx_http_flv_live版本(仅验证过1.2.5、1.2.9、1.2.11) |
---|---|
1.14.2 | 1.2.5~1.2.8(已验证1.2.5) |
1.15.12 | 1.2.5~1.2.8(已验证1.2.5) |
1.16.1 | 1.2.5~1.2.8(已验证1.2.5) |
1.17.10 | 1.2.5~1.2.8(已验证1.2.5) |
1.18.0 | 1.2.5~1.2.8(已验证1.2.5) |
1.19.10 | 1.2.9~1.2.11(已验证1.2.9) |
1.20.2 | 1.2.9~1.2.11(已验证1.2.9) |
1.21.6 | 1.2.9~1.2.11(已验证1.2.9) |
1.22.1 | 1.2.9~1.2.11(已验证1.2.9) |
1.23.4 | 1.2.9~1.2.11(已验证1.2.9) |
1.24.0 | 1.2.9~1.2.11(已验证1.2.9) |
1.25.5 | 1.2.9~1.2.11(已验证1.2.9、1.2.11) |
docker打包
下载好nginx和nginx_http_flv_live后解压到某一目录后在同级建立Dockerfile文件
FROM alpine:3.8.5
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update && apk add --no-cache gcc g++ make pcre zlib openssl
RUN apk add --no-cache pcre-dev openssl-dev
RUN mkdir -p /var/log/nginx/
COPY ./nginx-1.25.5 /home/nginx
COPY ./nginx-http-flv-module-1.2.11 /home/nginx-flv
RUN cd /home/nginx && ./configure --add-module=/home/nginx-flv && make && make install
RUN ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
CMD ["nginx", "-g", "daemon off;"]
编译
docker build -t nginx:1.25_flv .
环境搭建
nginx.conf
worker_processes auto;
events {
worker_connections 4096;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 5002;
location /live {
flv_live on;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
}
}
}
rtmp {
server {
listen 5001;
application live {
live on;
gop_cache off;
}
}
}
docker-compose.yaml
version: "0.0.1"
services:
nginx-flv:
image: nginx:1.25_flv
ports:
- 5002:5002
- 5001:5001
volumes:
- ./nginx.conf:/usr/local/nginx/conf/nginx.conf
restart: always
tty: true
推拉流方式
推流使用ffmpeg或obs推流尝试
拉流采用VLC或opencv拉流播放
RTMP推流格式:
rtmp://服务器地址:rtmp端口/app_name/stream_name
示例:rtmp://localhost:5001/live/mystream
HTTP-FLV拉流格式
http://服务器地址:http端口/服务地址?port=rtmp端口&app=app_name&stream=stream_name
http://localhost:5002/live?port=5001&app=live&stream=mystream