Files
wvp-platform/docker/nginx/templates/nginx.conf.template
16337 0afb3c42a4 适配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>
2026-02-03 11:10:06 +08:00

148 lines
5.4 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

server {
listen 8080;
server_name localhost;
location / {
root /opt/dist;
index index.html index.htm;
}
location /record_proxy/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://polaris-wvp:18978/;
}
location /api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://polaris-wvp:18978;
# 从环境变量获取原始主机地址x.x.x.x
set $original_host ${Stream_IP};
# 执行字符串替换
# 将媒体资源文件替换为Nginx输出的相对地址
sub_filter "http://$original_host/index/api/downloadFile" "mediaserver/api/downloadFile";
sub_filter "http://$original_host:80/index/api/downloadFile" "mediaserver/api/downloadFile";
sub_filter "https://$original_host/index/api/downloadFile" "mediaserver/api/downloadFile";
sub_filter "https://$original_host:443/index/api/downloadFile" "mediaserver/api/downloadFile";
sub_filter "http://$original_host/mp4_record" "mp4_record";
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;
# 确保响应被正确处理
sub_filter_types application/json; # 只对JSON响应进行处理
}
# 将mediaserver/record转发到目标地址
location /mediaserver/api/downloadFile {
# 目标服务器地址
proxy_pass http://polaris-media:80/index/api/downloadFile;
# 以下是常用的反向代理设置
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;
# 超时设置,根据需要调整
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
# 代理/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服务
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;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}