nginx and pseudostreaming with embedded perl and proxy

Sven 'Darkman' Michels sven at darkman.de
Fri Feb 1 19:51:53 UTC 2013


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



More information about the nginx mailing list