title: Distributed & Cached MP4 PseudoStreaming (seeking) with Nginx
body: <p>I tried to setup at least 2 servers with nginx (origin + edge). both compiled with the <a href="http://wiki.nginx.org/HttpMp4Module" rel="noreferrer">mp4</a>-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.</p>
  
  <p>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.</p>
  
  <p>nginx.conf @ origin:</p>
  
  <pre><code>server {
    listen       80;
    server_name  localhost;
    root         /usr/share/nginx/www;
    location ~ \.mp4$ {
      mp4;
      expires max;
    }
  }
  </code></pre>
  
  <p>nginx.conf @ edge:</p>
  
  <pre><code>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 &lt;origin-domain&gt;;
  }
  server {
    listen       80;
    server_name  localhost;
  
    location ~ \.mp4$ {
      mp4;
      proxy_cache icdn_cache;
      proxy_pass http://origin;
      proxy_cache_key $uri;
    }
  }
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>location / {
    location ~ \.mp4$ { mp4; }
    proxy_cache icdn_cache;
    proxy_pass http://origin;
    proxy_cache_key $uri;
  }
  </code></pre>
  
  <p>Is there a way to make cached mp4-files work with the seeking-function of mp4-module?</p>