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;