# Mp4 streaming + X-Accel-Redirect works on dev, fails on prod

**URL:** <https://www.ruby-forum.com/t/mp4-streaming-x-accel-redirect-works-on-dev-fails-on-prod/193808>\
**Category:** NGINX\
**Created:** [August 24, 2010, 7:07pm UTC](https://www.ruby-forum.com/t/mp4-streaming-x-accel-redirect-works-on-dev-fails-on-prod/193808 "2010-08-24T19:07:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [August 24, 2010, 7:07pm UTC](https://www.ruby-forum.com/t/mp4-streaming-x-accel-redirect-works-on-dev-fails-on-prod/193808/1 "2010-08-24T19:07:17Z")

</div>

Hi,

How come my Rails app that relies on Nginx to stream mp4 videos to flash  
and restricts access with X-Accel-Redirect, works on my dev machine but  
fails on the production server?

The config files are 99% the same: dev machine uses mongrel, prod  
machine uses passenger.

On the first request I see in my nginx and rails log a request to  
video.mp4?start=0

Then when I scrub, on my dev machine I see requests to  
video.mp4?start=12, etc. But nothing on my production server, the video  
restarts from the beginning.

Any idea? I’m sure it’s a stupid thing I’m missing here.

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [August 25, 2010, 7:14pm UTC](https://www.ruby-forum.com/t/mp4-streaming-x-accel-redirect-works-on-dev-fails-on-prod/193808/2 "2010-08-25T19:14:56Z")

</div>

Can someone quickly translate me what’s written in russian on this page:  
[http://permalink.gmane.org/gmane.comp.web.nginx.russian/35345](http://permalink.gmane.org/gmane.comp.web.nginx.russian/35345)

I’d like to know if it worked for him mp4+X-Accel-Redirect.

Thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [August 24, 2010, 10:06pm UTC](https://www.ruby-forum.com/t/mp4-streaming-x-accel-redirect-works-on-dev-fails-on-prod/193808/3 "2010-08-24T22:06:15Z")

</div>

It seems that the following was part of the culprit:

location ~ .mp4$ {  
mp4;  
}

By removing the $ sign at the ned of the regexp, I managed to make the  
streaming work. This also means the doc written by code-shop is wrong.

Anyway, now I need to tie everything up and combine mp4 with  
X-Accel-redirect.

I currently have the following which does not work:

location ~ /restricted/ {  
mp4;  
internal;  
}

But I’m not sure it can work out right. As /restricted is the direct  
access to the files, which must be prevented. In reality my flash player  
gets the file from /restricteds/some/other/path and behind the scenes  
Rails will set the appropriate headers.

This would mean that I’m missing a directive that would look like:

location ~ /restricteds/ {  
mp4;  
passenger\_enabled on;  
…  
}

Am I right?

Or maybe I cannot be done, and in order to secure the downloads I’ll  
have to use the secure download module?
