caching - 使用 Nginx 的分布式和缓存 MP4 伪流(搜索)

标签 caching nginx cdn mp4 pseudo-streaming

我尝试使用 nginx (origin + edge) 设置至少 2 台服务器。均使用 mp4 编译-模块。来源包含我所有的 mp4 文件。 Edge 配置了所有按预期工作的缓存内容(见下文),每个 mp4 文件请求第二次由边缘缓存提供服务,没有原始流量。

但我希望能够在文件中查找。该功能来自 mp4 模块。只需附加查询参数 "?start=120"告诉 nginx 从时间戳 120sec 开始提供 mp4 内容。这适用于直接请求的来源。但是一旦我在 nginx 的缓存位置启用 mp4-module,请求将是 404。

nginx.conf @起源:

server {
  listen       80;
  server_name  localhost;
  root         /usr/share/nginx/www;
  location ~ \.mp4$ {
    mp4;
    expires max;
  }
}

nginx.conf @ 边缘:
proxy_cache_path /usr/share/nginx/cache levels=2:2 keys_zone=icdn_cache:10m inactive=7d max_size=2g;
proxy_temp_path /usr/share/nginx/temp;
proxy_ignore_headers X-Accel-Expires Cache-Control Set-Cookie;
log_format cache '[$time_local] Cache: $upstream_cache_status $upstream_addr $upstream_response_time $status $bytes_sent $proxy_add_x_forwarded_for $request_uri';
access_log /usr/local/nginx/logs/cache.log cache;

upstream origin {
  server <origin-domain>;
}
server {
  listen       80;
  server_name  localhost;

  location ~ \.mp4$ {
    mp4;
    proxy_cache icdn_cache;
    proxy_pass http://origin;
    proxy_cache_key $uri;
  }
}

我也试过:
location / {
  location ~ \.mp4$ { mp4; }
  proxy_cache icdn_cache;
  proxy_pass http://origin;
  proxy_cache_key $uri;
}

有没有办法让缓存的 mp4 文件与 mp4-module 的搜索功能一起工作?

最佳答案

您必须使用 proxy_store . proxy_cache将为每个 ?start=xxxx 创建大量文件要求。

要让 mp4 模块在文件中查找,您需要完整的电影。 proxy_store将在缓存服务器上创建一个镜像。

关于caching - 使用 Nginx 的分布式和缓存 MP4 伪流(搜索),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10024981/

相关文章:

google-chrome - 在Chrome中播放WAV文件失败

Android Load Cache Only 不工作。离线显示 WebView

php - 在 PHP 中为方法结果缓存实现装饰器模式的最佳方法

web-services - 如何配置 nginx 来代理 SOAP Web 服务

php - 在 Nginx 中显示 PHP 错误而不是 502 Bad Gateway

http - 允许任何 CORS 源 (*) 时是否应设置 'Vary: Origin'?

html - 如果静态资源在 CDN 上,如何在本地调试站点?

javascript - 在像谷歌这样的快速免费 CDN 上托管您自己的 JavaScript 脚本文件(Jquery 除外)?

php - 独立使用 Symfony Routing 时如何缓存路由?

CSS 文件显示为垃圾