# Nginx and pseudostreaming with embedded perl and proxy

**URL:** <https://www.ruby-forum.com/t/nginx-and-pseudostreaming-with-embedded-perl-and-proxy/229606>\
**Category:** NGINX\
**Created:** [February 1, 2013, 8:52pm UTC](https://www.ruby-forum.com/t/nginx-and-pseudostreaming-with-embedded-perl-and-proxy/229606 "2013-02-01T20:52:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sven\_SDarkmanS\_Mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e99b99/32.png) [@Sven\_SDarkmanS\_Mich](https://www.ruby-forum.com/u/Sven_SDarkmanS_Mich)\
**Post date:** [February 1, 2013, 8:52pm UTC](https://www.ruby-forum.com/t/nginx-and-pseudostreaming-with-embedded-perl-and-proxy/229606/1 "2013-02-01T20:52:49Z")

</div>

Hi there,

i’ve the following setup:  
nginx as proxy in front of a central “storage” server who holds movies  
and pictures. So if a user requests some stuff, the proxy module fetches  
it from the central server and delivers it to the user. To protect some  
of the pictures and movies, i’ve written a small perl module which does  
some checks before the content is delivered. Its mainly an  
implementation of mod\_secdownload from lighty for creating expiring  
links. This works fine so far with one small limitation: movies cannot  
seeked. I enabled the mp4 module for the locations without any luck.

When i put a movie to the nginx server directly, it works. So i noticed  
that it might not work due to the proxy\_cache stuff (since the movie is  
not directly stored on the disc, it has the http headers added). So  
i switched to proxy\_store, which should work with the mp4 module. But  
still no look. Everytime i seek the movie starts from the beginning.  
Next idea: maybe the internal redirect stuff of the perl module breaks  
the pseudostreaming…?

nginx.conf looks like:

server {  
location ^~ /modcheck/ {  
internal;  
mp4;  
rewrite ^/modcheck/(.+)$ /$1 break;  
root /cache1/wwwroot;  
error\_page 404 = @fetch;  
}  
location @fetch {  
internal;  
proxy\_pass http://central\_store\_ip:8080;  
proxy\_set\_header Host central.server.tld;  
proxy\_store on;  
proxy\_store\_access user:rw group:r all:r;  
proxy\_temp\_path /cache1/temp;  
root /cache1/wwwroot;  
}  
location ~ “^/prot/someregexp/$” {  
perl modcheck::handler;  
}  
location / {  
proxy\_pass http://central\_store\_ip/;  
proxy\_set\_header Host central.domain.tld;  
proxy\_cache statics:  
proxy\_cache\_valid 200 1d;  
proxy\_cache\_use\_stale error timeout invalid\_header updating  
http\_500 http\_502 http\_503 http\_504;  
}  
}

So when a request for images.domain.tld/prot/stuff/file.mp4 hits nginx,  
it will be captured by the perl module, that will check if the request  
is fine so far and if yes, it will redirect the final url to the  
modcheck block. This block removes the modcheck part to get only the  
real filename and try to deliver the local file. If file is not found,  
it will be fetched first, then delivered. So generally this works fine  
so far. The redirect/perl stuff is also to avoid caching the same file  
multiple times.

Till the video skipping stuff this worked fine so far. Just the movie  
stuff only works when i put a movie to a local dir and deliver it  
directly. I can also copy the file from the proxy\_store, so the file  
itself is fine. nginx in this case is 1.1.19 - but also development  
showed the same issue.

Any ideas how to get this setup working like expected? Did i miss  
something? won’t that work at all maybe? If there is anything missing,  
just ask.

Thanks for your help!

Best wishes,  
Sven
