diff --git a/rtsp-vue/nginx.conf b/rtsp-vue/nginx.conf index ad6521f..788634e 100644 --- a/rtsp-vue/nginx.conf +++ b/rtsp-vue/nginx.conf @@ -50,37 +50,43 @@ 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; proxy_max_temp_file_size 0; - # 设置超时时间(视频流长连接)- 增加到2小时 + # 【关键】设置缓冲区为 0(强制立即转发) + proxy_buffer_size 0; + proxy_buffers 0 0; + proxy_busy_buffers_size 0; + + # 设置超时时间(视频流长连接) 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 "keep-alive"; - proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection ""; - # 响应头(CORS + 流媒体)- 使用 always 确保所有响应都有这些头 + # 【关键】响应头 - 禁用缓冲和缓存 + add_header X-Accel-Buffering no always; + add_header Cache-Control 'no-cache, no-store, must-revalidate' always; + add_header Pragma no-cache always; + add_header Expires 0 always; + + # CORS支持 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 优化 tcp_nopush off; tcp_nodelay on; + keepalive_timeout 0; } # 视频流代理(HLS)