适配Docker部署环境,修复拉流代理播放失败问题
1. Docker环境适配: - Dockerfile基础镜像从JDK11升级为eclipse-temurin:21 - pom.xml编译版本从Java21降为Java17 - docker-compose开放Redis(6379)、MySQL(3306)、ZLM(6080)端口映射 - application.yml激活profile改为dev - application-dev.yml适配Docker服务连接参数(Redis/MySQL/ZLM) 2. 修复拉流代理播放失败: - Nginx添加流媒体后缀代理规则(.flv/.m3u8/.ts等),支持自定义app名的流路径 - Nginx添加WebRTC API代理规则 - Nginx添加sub_filter规则,将API返回的流地址端口从80(ZLM容器内部端口)重写为8080(Nginx对外端口) - docker-compose向Nginx容器传递WebHttp环境变量 3. ZLMediaKit配置补充onvif和rtc相关配置段 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,8 +11,8 @@ services:
|
||||
start_period: 10s
|
||||
networks:
|
||||
- media-net
|
||||
# ports:
|
||||
# - 6379:6379
|
||||
ports:
|
||||
- 6379:6379
|
||||
volumes:
|
||||
- ./redis/conf/redis.conf:/opt/polaris/redis/redis.conf
|
||||
- ./volumes/redis/data/:/data
|
||||
@@ -37,8 +37,8 @@ services:
|
||||
MYSQL_USER: wvp_user
|
||||
MYSQL_PASSWORD: wvp_password
|
||||
TZ: Asia/Shanghai
|
||||
# ports:
|
||||
# - 3306:3306
|
||||
ports:
|
||||
- 3306:3306
|
||||
volumes:
|
||||
- ./mysql/conf:/etc/mysql/conf.d
|
||||
- ./logs/mysql:/logs
|
||||
@@ -59,7 +59,7 @@ services:
|
||||
networks:
|
||||
- media-net
|
||||
ports:
|
||||
#- "6080:80/tcp" # [播流]HTTP 安全考虑-非测试阶段需要注释掉,改为由nginx代理播流地址
|
||||
- "6080:80/tcp" # [播流]HTTP
|
||||
#- "4443:443/tcp" # [播流]HTTPS 安全考虑-非测试阶段需要注释掉,改为由nginx代理播流地址
|
||||
- "${MediaRtmp:-10935}:${MediaRtmp:-10935}/tcp" # [收流]RTMP
|
||||
- "${MediaRtmp:-10935}:${MediaRtmp:-10935}/udp" # [收流]RTMP
|
||||
@@ -148,6 +148,7 @@ services:
|
||||
environment:
|
||||
# 流链接的IP
|
||||
Stream_IP: ${Stream_IP}
|
||||
WebHttp: ${WebHttp:-8080}
|
||||
networks:
|
||||
- media-net
|
||||
|
||||
|
||||
@@ -196,4 +196,21 @@ pktBufSize=8192
|
||||
port=9000
|
||||
timeoutSec=5
|
||||
|
||||
; } ---
|
||||
[onvif]
|
||||
port=3702
|
||||
|
||||
[rtc]
|
||||
enableTurn=1
|
||||
icePort=3478
|
||||
icePwd=ZLMediaKit
|
||||
iceTcpPort=3478
|
||||
iceTransportPolicy=0
|
||||
iceUfrag=ZLMediaKit
|
||||
interfaces=
|
||||
max_stun_retry=7
|
||||
nackAudioRtpSize=4
|
||||
port_range=49152-65535
|
||||
preferred_tcp=0
|
||||
signalingPort=3000
|
||||
signalingSslPort=3001
|
||||
|
||||
|
||||
@@ -34,6 +34,14 @@ server {
|
||||
sub_filter "http://$original_host:80/mp4_record" "mp4_record";
|
||||
sub_filter "https://$original_host/mp4_record" "mp4_record";
|
||||
sub_filter "https://$original_host:443/mp4_record" "mp4_record";
|
||||
|
||||
# 将流播放地址中的端口80替换为Nginx对外端口8080
|
||||
sub_filter "http://$original_host:80/" "http://$original_host:${WebHttp}/" ;
|
||||
sub_filter "ws://$original_host:80/" "ws://$original_host:${WebHttp}/" ;
|
||||
sub_filter "wss://$original_host:443/" "wss://$original_host:${WebHttp}/" ;
|
||||
sub_filter "https://$original_host:443/" "https://$original_host:${WebHttp}/" ;
|
||||
sub_filter "http://$original_host/" "http://$original_host:${WebHttp}/" ;
|
||||
sub_filter "ws://$original_host/" "ws://$original_host:${WebHttp}/" ;
|
||||
|
||||
# 设置为off表示替换所有匹配项,而不仅仅是第一个
|
||||
sub_filter_once off;
|
||||
@@ -59,28 +67,57 @@ server {
|
||||
proxy_read_timeout 300s;
|
||||
}
|
||||
|
||||
# 仅允许代理/rtp/开头的路径
|
||||
# 代理/rtp/开头的路径(国标设备流)
|
||||
location ^~ /rtp/ {
|
||||
# 代理到ZLMediakit服务
|
||||
proxy_pass http://polaris-media:80;
|
||||
|
||||
|
||||
# 基础HTTP代理配置
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
|
||||
# WebSocket支持配置
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
|
||||
|
||||
# 超时设置,根据实际需求调整
|
||||
proxy_connect_timeout 60s;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 60s;
|
||||
}
|
||||
|
||||
# 代理流媒体播放请求到ZLMediaKit(匹配 .flv/.mp4/.m3u8/.ts 等流媒体后缀)
|
||||
location ~* \.(live\.flv|live\.mp4|live\.ts|m3u8|flv|ts)$ {
|
||||
proxy_pass http://polaris-media:80;
|
||||
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# WebSocket支持
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
|
||||
proxy_connect_timeout 60s;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 60s;
|
||||
}
|
||||
|
||||
# 代理 ZLMediaKit WebRTC API
|
||||
location ^~ /index/api/webrtc {
|
||||
proxy_pass http://polaris-media:80;
|
||||
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# 仅允许代理/rtp/开头的路径
|
||||
location ^~ /mp4_record/ {
|
||||
# 代理到ZLMediakit服务
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM ringcentral/jdk:11 AS builder
|
||||
FROM eclipse-temurin:21-jdk AS builder
|
||||
|
||||
EXPOSE 18978/tcp
|
||||
EXPOSE 8116/tcp
|
||||
@@ -56,11 +56,11 @@ COPY . /build
|
||||
WORKDIR /build
|
||||
RUN ls && mvn clean package -Dmaven.test.skip=true
|
||||
WORKDIR /build/target
|
||||
#ȷ<><C8B7><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>һ<EFBFBD><D2BB>
|
||||
#ȷ<><C8B7><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>һ<EFBFBD><D2BB>
|
||||
RUN mv wvp-pro-*.jar wvp.jar
|
||||
|
||||
|
||||
FROM ringcentral/jdk:11
|
||||
FROM eclipse-temurin:21-jre
|
||||
RUN mkdir -p /opt/wvp
|
||||
WORKDIR /opt/wvp
|
||||
COPY --from=builder /build/target /opt/wvp
|
||||
|
||||
4
pom.xml
4
pom.xml
@@ -60,8 +60,8 @@
|
||||
<asciidoctor.html.output.directory>${project.build.directory}/asciidoc/html</asciidoctor.html.output.directory>
|
||||
<asciidoctor.pdf.output.directory>${project.build.directory}/asciidoc/pdf</asciidoctor.pdf.output.directory>
|
||||
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
|
||||
@@ -20,18 +20,18 @@ spring:
|
||||
# [必须修改] 端口号
|
||||
port: 6379
|
||||
# [可选] 数据库 DB
|
||||
database: 7
|
||||
database: 0
|
||||
# [可选] 访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接
|
||||
password: luna
|
||||
# password:
|
||||
# [可选] 超时时间
|
||||
timeout: 10000
|
||||
# mysql数据源
|
||||
datasource:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/wvp273数据库统合?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true&serverTimezone=PRC&useSSL=false&allowMultiQueries=true&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: 12345678
|
||||
url: jdbc:mysql://127.0.0.1:3306/wvp?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true&serverTimezone=PRC&useSSL=false&allowMultiQueries=true&allowPublicKeyRetrieval=true
|
||||
username: wvp_user
|
||||
password: wvp_password
|
||||
# h2数据库
|
||||
# datasource:
|
||||
# driver-class-name: org.h2.Driver
|
||||
@@ -82,11 +82,11 @@ sip:
|
||||
media:
|
||||
id: zlmediakit-local
|
||||
# [必须修改] zlm服务器的内网IP
|
||||
ip: 192.168.1.10
|
||||
ip: 127.0.0.1
|
||||
# [必须修改] zlm服务器的http.port
|
||||
http-port: 9092
|
||||
http-port: 6080
|
||||
# [必选选] zlm服务器的hook.admin_params=secret
|
||||
secret: TWSYFgYJOQWB4ftgeYut8DW4wbs7pQnj
|
||||
secret: su6TiedN2rVAmBbIDX0aa0QTiBJLBdcf
|
||||
# 启用多端口模式, 多端口模式使用端口区分每路流,兼容性更好。 单端口使用流的ssrc区分, 点播超时建议使用多端口测试
|
||||
rtp:
|
||||
# [可选] 是否启用多端口模式, 开启后会在portRange范围内选择端口用于媒体流传输
|
||||
|
||||
@@ -2,4 +2,4 @@ spring:
|
||||
application:
|
||||
name: wvp
|
||||
profiles:
|
||||
active: 274-dev
|
||||
active: dev
|
||||
|
||||
Reference in New Issue
Block a user