Home  >  Q&A  >  body text

linux - Nginx做视频缓存,怎样边回源边响应给用户

用Nginx的proxy功能,在客户请求一个70mb的文件时,Nginx用1mb/s的速度去视频网站下载这个mp4文件,客户那里一直黑屏,直到70s后,Nginx以8mb/s的速度将完整的mp4文件传给了用户,视频才播放起来。 这样做的话,面对一个未缓存的新视频,第一个访问的用户要等70s才能看,有点麻烦。请问有什么好的解决方案吗?目前想的是用爬虫来假装第一个用户,但这样也只是解决了热门视频的问题。 请不吝赐教

大家讲道理大家讲道理2742 days ago749

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 14:56:16

    proxy_buffering off

    nginx turns on proxy_buffering by default. It will try its best to read the responses data and temporarily save it, and then send it to the customer after receiving it.
    After proxy_buffering is turned off, nginx will immediately send the obtained mp4 data to the client. After the client collects enough metadata for playback, it can start playing, usually very quickly (if the file itself is not suitable for streaming media playback, it is another problem. It happened, but it’s rare anymore)

    SF’s first answer, please correct me if I am wrong.

    Reference documentation: http://nginx.org/en/docs/http...

    reply
    0
  • Cancelreply