【问题标题】:Can you retrieve and store a file from a backend server before searching for the nginx location?您可以在搜索 nginx 位置之前从后端服务器检索和存储文件吗?
【发布时间】:2016-01-11 20:48:58
【问题描述】:

问题

我正在使用 Nginx Plus 中的 HLS 模块来流式传输 .mp4 文件,使用以下配置:

    location /hls {
        hls;
        hls_fragment 10s;
        hls_buffers 10 10m;
        hls_mp4_buffer_size 1m;
        hls_mp4_max_buffer_size 10m;
        alias /var/www/vod/cache;
    }

当 .mp4 文件存在于 /var/www/vod/cache 中时,一切正常。当客户端请求http://example.com/hls/file.mp4.m3u8 时,HLS 模块会即时生成 m3u8 播放列表并返回。

但是,我不希望将所有 mp4 文件都存储在流媒体服务器上,而是将文件存储在后端存储服务器上。理想情况下,mp4 文件只会在客户端请求特定视频时从存储服务器检索并存储在本地(稍后将通过 cron 作业删除)。使用 proxy_store,我可以检索 mp4 文件并使用如下配置将它们存储在本地:

    location @fetch_content {
        internal;
        rewrite ^/hls(.*).mp4.m3u8$ $1.mp4 break;
        proxy_pass         http://example-storage.com;
        proxy_store        on;
        proxy_store_access user:rw group:rw all:r;
        proxy_temp_path    /tmp;
        root /var/www/vod/cache;
    }

使用proxy_pass的问题是nginx直接返回mp4文件给客户端,而不是m3u8播放列表。

是否可以让 nginx 检索并存储 mp4 文件,然后使用 HLS 模块生成 m3u8 播放列表文件?或者换一种说法,我可以检查 mp4 文件是否存在,如果找不到,则检索并存储它,然后点击将使用 HLS 模块流式传输文件的 /hls 位置?

由于这是 Nginx Plus,我无法编写模块。我只能使用包含的模块,看这里https://www.nginx.com/products/technical-specs/

【问题讨论】:

  • 我不认为那里已经实现了这种非平凡和非正统的逻辑;-) 为什么不简单地将远程服务器安装为磁盘卷?让 nginx 认为所有文件都是本地的?

标签: nginx nginx-location


【解决方案1】:

Nginx Plus 包括第 3 方 Lua module,我能够在定向到 /hls 位置之前使用 Lua 从后端服务器检索 mp4 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-24
    • 2015-12-04
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    相关资源
    最近更新 更多