You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用lighttpd反向代理Motion JPEG摄像头流失败求助

问题描述

我将RTSP摄像头流通过ffmpeg-server转换为Motion JPEG流,ffmpeg-server提供的流可通过http://localhost:8090/still.jpg和http://localhost:8090/live.mjpg访问。现在希望通过lighttpd将该流代理到http://localhost:8080/live.mjpg(端口变更),但配置后仅能正常访问still.jpg,live.mjpg无法访问。

我的lighttpd配置如下:

$HTTP["url"] =~ "(^/still.jpg)" {   
  proxy.server = ( "" => ("" => ( "host" => "localhost", "port" => 8090 ))) 
}
$HTTP["url"] =~ "(^/live.mjpg)" {
    proxy.server = ( "" => ("" => ( "host" => "localhost", "port" => 8090 ))) 
}

访问情况:

  • 正常:http://localhost:8090/still.jpg
  • 正常:http://localhost:8090/live.mjpg
  • 正常:http://localhost:8080/still.jpg
  • 失败:http://localhost:8080/live.mjpg

推测问题在于lighttpd虽正确转发请求,但因后端请求未完成,未将响应转发给客户端,请问能否让lighttpd分块转发可用的响应内容?


解决方案

Motion JPEG流属于流式响应,后端不会一次性返回完整内容,而是持续分块输出。lighttpd默认会缓冲后端响应,直到完整接收后再转发给客户端,这就导致流式的live.mjpg无法正常显示。

你需要在lighttpd配置中针对live.mjpg的代理规则添加禁用缓冲、开启流式转发的设置:

修改后的配置如下:

$HTTP["url"] =~ "(^/still.jpg)" {   
  proxy.server = ( "" => ("" => ( "host" => "localhost", "port" => 8090 ))) 
}
$HTTP["url"] =~ "(^/live.mjpg)" {
    proxy.server = ( "" => ("" => ( "host" => "localhost", "port" => 8090 )))
    # 禁用代理缓冲,实时转发后端分块数据
    proxy.buffering = "disable"
    # 启用分块传输编码,适配流式输出
    proxy.chunked = "enable"
}

配置说明

  • proxy.buffering = "disable":关闭lighttpd对后端响应的缓冲,让服务器一收到后端的分块数据就立刻转发给客户端。
  • proxy.chunked = "enable":强制启用分块传输编码,匹配Motion JPEG的流式输出特性,确保响应能被客户端正确解析。

修改配置后重启lighttpd服务,再访问http://localhost:8080/live.mjpg即可正常加载流。

内容的提问来源于stack exchange,提问作者Maximilian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 06:22:18