# MP4 module and X-Accel-Redirect

**URL:** <https://www.ruby-forum.com/t/mp4-module-and-x-accel-redirect/219120>\
**Category:** NGINX\
**Created:** [April 21, 2012, 2:19am UTC](https://www.ruby-forum.com/t/mp4-module-and-x-accel-redirect/219120 "2012-04-21T02:19:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 21, 2012, 2:19am UTC](https://www.ruby-forum.com/t/mp4-module-and-x-accel-redirect/219120/1 "2012-04-21T02:19:36Z")

</div>

Hello

I currently have a setup involving nginx-extras (1.1.19) and PHP,  
making heavy use of the X-Accel-Redirect heades to serve files with  
previous authentication. This also enables range requests and so on,  
which work flawlessly.

Sadly, I can’t seem to make this approach work with the MP4 streaming  
module. It works as expected with a standalone mp4 file and the  
?start= parameter works just fine. But passing a request like this:

/request?token=xxx&start=60

Does not work and yields the entire file instead.

My config approach is the following:

location ~ .php$ {  
internal;

```
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;

fastcgi_index index.php;

include fastcgi_params;

fastcgi_pass 127.0.0.1:9000;

```

}

location ~ .mp4$ {  
mp4;  
}

location /files/ {  
rewrite\_by\_lua ’  
…misc script to track connections…  
';  
internal;  
mp4;  
alias /home/service/files/;  
}

location /priority {  
mp4;  
rewrite ^ /request.php last;  
}

I cannot try any more or different combinations for the mp4 directive,  
I’ve tried to put it everywhere and just in a few places, and still,  
can’t manage to get anything. Some time Google shows some message  
similar to this but dead in the wind without answer.

Thank you for your time.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 22, 2012, 4:05am UTC](https://www.ruby-forum.com/t/mp4-module-and-x-accel-redirect/219120/2 "2012-04-22T04:05:00Z")

</div>

I have finally resorted to a mixed approach:

- I generate symbolic links (ln -s) from the concealed ‘internal’  
location to a folder in the public root, only for the files I need
- That folder has a location {} directive, containing the mp4;  
parameter to enable streaming support
- This location has an access\_by\_lua directive, which passes, using  
ngx.location.capture, a copy of the request to a local API (written in  
PHP) and validates the access
- Also rate limiting

That way I can mimic the usual approach where PHP does all these  
checks, in a much more complicated way… But still, it works.

On Sat, Apr 21, 2012 at 2:18 AM, Adrián Navarro [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> fastcgi_read_timeout 300;
> }
> location /priority {
> 
> ```
> 
> Thank you for your time.  
> –  
> Adrián Navarro / (+34) 608 831 094
