-1

I tried whole day to make an nginx vhost config to acomplish my needs but i make it wrong all the time. Here is what i need to do.

I have a server in which i stream Movies & Live Streams. The Movies & Streams are being restreamed from a .php file . Everything is fine with this. These 2 files are stream_live.php and stream_movies.php

I want to use different fastcgi_ settings depending on the type value i will select. For example for livestreams you can select to be in mpegts or hls. I want this as a parameter in PHP File. Now i will give examples in order to understand it better.

I want each time a user requests like this:

http://domain.com/live/username/password/1.live?type=hls

to be redirected in the file stream_live.php with parameteres username,password,id and type (1 = id here). How i can do that?

And for the movies i want a similar one like

http://domain.com/movies/username/password/1.movie

to be redirected in the file stream_movies with parameterers Username/Password/ID (1 = ID)

One small note! As i said above i want to use different settings if you are requesting movies or live streams.

So for movies i want to use

  • fastcgi_buffering off;

For Live Streams i want to use

  • fastcgi_buffering on; EXCEPT in type=hls which i want it fastcgi_buffering off;

Sorry that i'm requesting the whole nginx config but i tried whole day to make it and i couldn't. :(

Thank you

3

So basically you want to control just the fastcgi_buffering setting based on the type parameter? Read the fine manual and notice this part:

Buffering can also be enabled or disabled by passing “yes” or “no” in the “X-Accel-Buffering” response header field. This capability can be disabled using the fastcgi_ignore_headers directive.

So, to simplify this, use a simple nginx configuration for routing:

location /movies/ {
    include fastcgi_params;
    fastcgi_pass ...;
    fastcgi_param SCRIPT_FILENAME /path/to/stream_movies.php;
}
location /live/ {
    include fastcgi_params;
    fastcgi_pass ...;
    fastcgi_param SCRIPT_FILENAME /path/to/stream_live.php;
}

... and in PHP you should send the X-Accel-Buffering: no header field to disable buffering. For plain PHP you could use something like:

if (filter_input(INPUT_GET, 'type') == 'hls') {
    // buffering is on by default, disable it for HLS
    header('X-Accel-Bufferring: no');
}

Remember that the default value for fastcgi_buffering is on. Adjust the logic above to your needs.

  • Thank you. omg. I didn't know that :/. And one last question. How do i pass the parameters such as username/password/id ? I need the rewrite module right? – user3393046 Sep 21 '14 at 14:16
  • @user3393046 You could do that at nginx level using rewrite, but you could also make PHP parse the URL. – Lekensteyn Sep 21 '14 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.