From 182f0455176165eb24ed23c0d30466ed407aac0d Mon Sep 17 00:00:00 2001 From: 86156 <823267011@qq.com> Date: Wed, 1 Oct 2025 23:27:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B7=A5=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rtsp-vue/nginx.conf | 25 ++++++++++++++++--------- rtsp-vue/vite.config.js | 19 ++++++++++++++++++- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/rtsp-vue/nginx.conf b/rtsp-vue/nginx.conf index 096f08c..ad6521f 100644 --- a/rtsp-vue/nginx.conf +++ b/rtsp-vue/nginx.conf @@ -50,30 +50,37 @@ server { proxy_pass http://127.0.0.1:10083/live; proxy_http_version 1.1; - # 重要:禁用所有缓冲,实时传输视频流 + # 关键:禁用所有缓冲,立即转发数据 proxy_buffering off; proxy_cache off; proxy_request_buffering off; - chunked_transfer_encoding on; + proxy_max_temp_file_size 0; # 设置超时时间(视频流长连接)- 增加到2小时 proxy_connect_timeout 120s; proxy_send_timeout 7200s; proxy_read_timeout 7200s; - # 请求头 + # 请求头(保持连接) 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 Connection ""; + proxy_set_header Connection "keep-alive"; + proxy_set_header Upgrade $http_upgrade; - # CORS支持 - add_header Access-Control-Allow-Origin *; - add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; - add_header Access-Control-Allow-Headers '*'; + # 响应头(CORS + 流媒体)- 使用 always 确保所有响应都有这些头 + add_header Access-Control-Allow-Origin * always; + add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS' always; + add_header Access-Control-Allow-Headers '*' always; + add_header Cache-Control 'no-cache, no-store, must-revalidate' always; + add_header Pragma 'no-cache' always; + add_header X-Accel-Buffering 'no' always; - # 禁用限速 + # 禁用限速和缓存 proxy_limit_rate 0; + sendfile off; + tcp_nopush off; + tcp_nodelay on; } # 视频流代理(HLS) diff --git a/rtsp-vue/vite.config.js b/rtsp-vue/vite.config.js index 2b6f847..795a97a 100644 --- a/rtsp-vue/vite.config.js +++ b/rtsp-vue/vite.config.js @@ -31,9 +31,26 @@ export default defineConfig(({ mode, command }) => { proxy: { // https://cn.vitejs.dev/config/#server-proxy '/dev-api': { - target: 'http://localhost:8080', + target: 'http://localhost:10081', changeOrigin: true, rewrite: (p) => p.replace(/^\/dev-api/, '') + }, + // 视频流代理(HTTP-FLV) + '/live': { + target: 'http://localhost:10083/live', + changeOrigin: true, + // 关键:禁用所有缓冲,实时转发 + configure: (proxy, options) => { + proxy.on('proxyReq', (proxyReq, req, res) => { + console.log('🎬 代理视频流请求:', req.url); + }); + proxy.on('proxyRes', (proxyRes, req, res) => { + console.log('📺 收到视频流响应,开始转发...'); + // 禁用缓冲 + proxyRes.headers['x-accel-buffering'] = 'no'; + proxyRes.headers['cache-control'] = 'no-cache'; + }); + } } } },