From 765abf750977b4c6de64207a82e3f580f80c2477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=B0=8F=E4=BA=91?= Date: Mon, 8 Dec 2025 19:45:17 +0800 Subject: [PATCH] xx --- docker/nginx/templates/nginx.conf.template | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/docker/nginx/templates/nginx.conf.template b/docker/nginx/templates/nginx.conf.template index cf0de13..38a727a 100644 --- a/docker/nginx/templates/nginx.conf.template +++ b/docker/nginx/templates/nginx.conf.template @@ -5,6 +5,15 @@ server { location / { root /opt/dist; index index.html index.htm; + } + # 转发 ZLMediaKit 接口(如 /index/api/webrtc) + location ^~ /index/ { + 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_set_header X-Forwarded-Proto $scheme; + proxy_pass http://polaris-media:80; } location /record_proxy/{ proxy_set_header Host $http_host; @@ -30,10 +39,18 @@ server { 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"; + # 回放/录像走真实host:port,避免生成无端口的ws地址 + sub_filter "http://$original_host/mp4_record" "$scheme://$http_host/mp4_record"; + sub_filter "http://$original_host:80/mp4_record" "$scheme://$http_host/mp4_record"; + sub_filter "https://$original_host/mp4_record" "$scheme://$http_host/mp4_record"; + sub_filter "https://$original_host:443/mp4_record" "$scheme://$http_host/mp4_record"; + # 播放地址使用真实访问的host(包含端口),避免返回裸IP导致404 + sub_filter "http://$original_host/rtp/" "$scheme://$http_host/rtp/"; + sub_filter "http://$original_host:80/rtp/" "$scheme://$http_host/rtp/"; + sub_filter "ws://$original_host/rtp/" "ws://$http_host/rtp/"; + sub_filter "ws://$original_host:80/rtp/" "ws://$http_host/rtp/"; + sub_filter "http://$original_host/index/api/webrtc" "$scheme://$http_host/index/api/webrtc"; + sub_filter "http://$original_host:80/index/api/webrtc" "$scheme://$http_host/index/api/webrtc"; # 设置为off表示替换所有匹配项,而不仅仅是第一个 sub_filter_once off;