reverse proxying video streaming

Maxim Dounin mdounin at mdounin.ru
Wed Apr 13 15:43:29 MSD 2011


Hello!

On Wed, Apr 13, 2011 at 05:38:25PM +0700, Hari Hendaryanto wrote:

> hi,
> 
> i've successfully reverse proxying streaming content through nginx.
> 
> this is my config
> 
>         location /stream/ {
>             proxy_pass         http://xxx.xxx.xxx.xxx:8080/stream.flv;
>             proxy_redirect     off;
> 
>             proxy_set_header   Host             $host;
>             proxy_set_header   X-Real-IP        $remote_addr;
>             proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
>         }
> 
> open via browser http://www.example.com/stream/  success,without problem.
> 
> however, i need to append fake uri such as
> http://www.example.com/stream/stream/content.flv
> 
> here's what i've done so far
> 
>         location /stream/content.flv {
>             proxy_pass         http://xxx.xxx.xxx.xxx:8080/stream.flv;
>             proxy_redirect     off;
> 
>             proxy_set_header   Host             $host;
>             proxy_set_header   X-Real-IP        $remote_addr;
>             proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
>         }
> 
> it's always pointed to /var/www/html/stream/content.flv
> 
> [error] 24546#0: *1 open() "/var/www/html/stream/content.flv" failed
> (2: No such file or directory)
> 
> any clues?

Most likely you have some regexp location in your config which 
matches *.flv.

If you need exact match - most obvious solution is to use exact 
match location instead, i.e.

    location = /stream/content.flv {
        ...
    }

Exact match locations are considered most specific and prevent 
testing of regexp locations.  The same for normal static locations 
may be achieved via "^~" (no regexp) modifier.

Alternative aproach is to properly isolate regexp locations by 
nesting them into appropriate normal locations, i.e.  do something 
like

    location / { 
        ...

        location ~ \.flv$ {
            ...
        }
    }

    location /stream/ {
        ...
    }

This is actually recommended, but not exactly required in your 
case as it looks like you need exact match anyway.

Maxim Dounin



More information about the nginx mailing list