Distributed & Cached MP4 PseudoStreaming (seeking) with Nginx
Asked Answered
G

2

9

I tried to setup at least 2 servers with nginx (origin + edge). both compiled with the mp4-module. The origin holds all my mp4-files. Edge is configured with all the caching-stuff (see below) that work as expected, each mp4-file request a second time is served by the edge-cache without origin traffic.

But I want to be able to seek in the file. The functionality comes from the mp4-module. Just append the query-param "?start=120" tells nginx to serve the mp4-content starting with timestamp 120sec. This works fine with origin directly requested. But as soon as i enable mp4-module in the caching-location of the nginx, the request will be 404.

nginx.conf @ origin:

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

nginx.conf @ edge:

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;
  }
}

I also tried:

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

Is there a way to make cached mp4-files work with the seeking-function of mp4-module?

Grandmotherly answered 5/4, 2012 at 8:15 Comment(0)
G
0

You must use proxy_store. proxy_cache will create a lot of files for every ?start=xxxx request.

To let an mp4 module seek in files you need the full movie. proxy_store will make a mirror on the cache server.

Gillette answered 23/5, 2012 at 15:29 Comment(1)
That is not true, because the user is using 'proxy_cache_key $uri;' the proxy_cache will use $uri (rather than $request_uri) as the key, $uri does not include the query params. This may actually cause a problem, if the first request has ?start=120 and nginx caches the file with the first 120 seconds missing, but that is a different issueAvera
C
0

proxy_cache is part of proxy module. Currently you can't use nginx mp4 module with proxy, it only works for static files, that's it.

Chiasma answered 11/2, 2014 at 19:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.