flv streaming and proxy_pass

Karolis D karolis at pg.lt
Thu Feb 19 02:15:39 MSK 2009

On Wed, Feb 18, 2009 at 7:39 PM, Karolis <karolis at pg.lt> wrote:

> hi list,
> I am using nginx / apache combination to stream flv files.
> Nginx serves static files and forwards dynamic requests to apache/mod_php.
> Request flow would be as follows:
> - client requests some file
> - nginx rewrites the filename to a local cache dir
> - if file is found in the cache dir, nginx sends the file
> - if file is not found, then request is passed to apache, which will create
> the file and send the contents.
> For flv files we want flv streaming.
> The rules I am using to make this work are as follows:
>   # Map request url to cache dir
>   location /dbfile {
>           rewrite  "^/dbfile/([0-9]{3})([0-9]{3})([0-9]{3})/(.*)$"
> /cache/$1/$2/$1$2$3__$4  last;
>   }
>   # Forward PHP requests to apache, in case we don't have cache yet
>   location ~ ^/cache/ {
>       if (!-f $request_filename) {
>           proxy_pass;
>       break;
>       }
>   }
>   # Handle FLV streaming
>   location ~ ^/cache/(.*)\.flv$ { flv; }
> In this configuration, proxy_pass works, but flv streaming doesn't.
> If I move FLV "location" directive above proxy_pass, then flv will work,
> and proxy_pass won't.
> How do I get them both to work together? I don't want streaming of proxied
> requests, I only want to
> flv-stream the files that are on local filesystem.
> Any help?
> thanks
> Karolis
I've also tried to work around the problem by rewriting flv file to php
script, and then proxy_pass'ing the php to apache, but the results are no

    # Map request url to cache dir
    location ~ ^/dbfile/ {
            rewrite  "^/dbfile/([0-9]{3})([0-9]{3})([0-9]{3})/(.*)$"
/cache/$1/$2/$1$2$3__$4  last;

        # If required cache file does not exist...
    location ~ ^/cache/ {
        if (!-f $request_filename) {
            rewrite "/cache/([0-9]{3})/([0-9]{3})/([0-9]{9})__(.*)$"
/file.php?id=$3 last;

        location ~ ^/cache/(.*)\.flv$ { flv; }

    # Forward PHP requests to Apache
    location ~ ^/file.php {
        proxy_pass; # pass on request to apache

If I comment out the proxy_pass section, then the FLV streaming starts to
work fine. So it kind of means nginx doesn't like the proxy part of the

I do understand that you can't stream a file that is retrieved from a proxy
server, but in this setup  I am trying to do only one of those things:
Either fetch the file from proxy if it doesn't exist locally, or flv-stream
it if it does exist.

Problem is that lighttpd does it without a problem with mod_magnet :)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20090219/0b2a9abe/attachment.html>

More information about the nginx mailing list