Forum: NGINX Limit_rate for different resolutions!

13731c628e20ffd83b6114ff2c406272?d=identicon&s=25 shahzaib mushtaq (shahzaib12)
on 2013-07-20 11:30
(Received via mailing list)
Hello,

      Is there a way that i could use different limit_rate in nginx for
different files ? I.e

1. limit_rate 500k for 720p video files.
2. limit_rate 180k for 320p video files.


Best Regards.
Shahzaib
36a8284995fa0fb82e6aa2bede32adac?d=identicon&s=25 Francis Daly (Guest)
on 2013-07-20 11:36
(Received via mailing list)
On Sat, Jul 20, 2013 at 02:29:49PM +0500, shahzaib shahzaib wrote:

Hi there,

>       Is there a way that i could use different limit_rate in nginx for
> different files ? I.e
>
> 1. limit_rate 500k for 720p video files.
> 2. limit_rate 180k for 320p video files.

Yes.

http://nginx.org/r/limit_rate

One possibility: have your 720p video files and your 320p video files
handled in different location{} blocks.

  f
--
Francis Daly        francis@daoine.org
13731c628e20ffd83b6114ff2c406272?d=identicon&s=25 shahzaib mushtaq (shahzaib12)
on 2013-07-20 11:48
(Received via mailing list)
Hello Francis,

what if both(720p,360p) are in same directory i.e /var/www/html/videos ?
36a8284995fa0fb82e6aa2bede32adac?d=identicon&s=25 Francis Daly (Guest)
on 2013-07-20 11:58
(Received via mailing list)
On Sat, Jul 20, 2013 at 02:47:14PM +0500, shahzaib shahzaib wrote:

Hi there,

> what if both(720p,360p) are in same directory i.e /var/www/html/videos ?

Where's the problem?

http://nginx.org/r/limit_rate for limit_rate.

http://nginx.org/r/location, if you choose to handle the different types
of files in different location{} blocks.

  f
--
Francis Daly        francis@daoine.org
13731c628e20ffd83b6114ff2c406272?d=identicon&s=25 shahzaib mushtaq (shahzaib12)
on 2013-07-21 10:48
(Received via mailing list)
Hello,

     Following two are the file types whom i want to assign different
rate_limits :

http://domain.com/files/videos/2013/07/20/13743016...  --->
limit_rate 180k;
http://domain.com/files/videos/2013/07/20/13743016... -->
limit_rate 500;

Following is the virtualhost config :


server {
        listen  80;
        server_name  domain.com;

        client_max_body_size 800m;
        limit_rate 180k;
    #    access_log  /websites/theos.in/logs/access.log  main;

        location / {
            root   /var/www/html/videos;
            index index.html index.htm index.php;

}

location ~ \.(flv|jpg|jpeg)$ {
                flv;
                root /var/www/html/videos;
               expires 7d;
                valid_referers none blocked domain.com;
                if ($invalid_referer) {
                    return   403;
                }
                }
location ~ \.(mp4)$ {
                mp4;
                root /var/www/html/videos;
                expires 7d;
}

Can you please guide me a bit that how to configure the specific
limit_rate
in different location{} blocks? I am a bit confused on it :(

Thanks
36a8284995fa0fb82e6aa2bede32adac?d=identicon&s=25 Francis Daly (Guest)
on 2013-07-21 11:07
(Received via mailing list)
On Sun, Jul 21, 2013 at 01:47:57PM +0500, shahzaib shahzaib wrote:

Hi there,

>      Following two are the file types whom i want to assign different
> rate_limits :
>
> http://domain.com/files/videos/2013/07/20/13743016...  --->
> limit_rate 180k;
> http://domain.com/files/videos/2013/07/20/13743016... -->
> limit_rate 500;

What rate limit do you want to apply to http://domain.com/file.flv?

What rate limit actually applies to it? And did you measure it? ("curl"
is usually a good tool to see what is really happening.)

>         location / {
> location ~ \.(flv|jpg|jpeg)$ {
> location ~ \.(mp4)$ {

http://nginx.org/r/location

What do your "location" lines up there mean?

For each request you make, what one location is used?

What happens if you add a

  location ~ -720\.mp4$ {}

block at the end? And what happens if you instead add it at the start?

  f
--
Francis Daly        francis@daoine.org
13731c628e20ffd83b6114ff2c406272?d=identicon&s=25 shahzaib mushtaq (shahzaib12)
on 2013-07-21 11:25
(Received via mailing list)
Hello,

      I added the 720p in the location{} and checked it by downloading
the
single file using wget and got the 500K speed :).

location ~ -720\.(mp4)$ {
                mp4;
                expires 7d;
                limit_rate 500k;
                root /var/www/html/tunefiles;
}
That worked :). Thanks a lot @francis.
13731c628e20ffd83b6114ff2c406272?d=identicon&s=25 shahzaib mushtaq (shahzaib12)
on 2013-07-21 11:30
(Received via mailing list)
What rate limit actually applies to it? And did you measure it? ("curl"
is usually a good tool to see what is really happening.)

>         location / {
> location ~ \.(flv|jpg|jpeg)$ {
> location ~ \.(mp4)$ {

Well the rate_limit was 180K before for all the files because i added it
into the server{} block and these location blocks were actually means
the
rate_limit 180k will apply to any flv,mp4,jpeg file and after adding
-720
before the location ~\.(mp4)$, the only 720p files will be served on
limit_rate 500k and the rest would remain the same which is 180k in my
case.

I didn't used curl instead wget.
36a8284995fa0fb82e6aa2bede32adac?d=identicon&s=25 Francis Daly (Guest)
on 2013-07-21 22:13
(Received via mailing list)
On Sun, Jul 21, 2013 at 02:29:26PM +0500, shahzaib shahzaib wrote:

Hi there,

> Well the rate_limit was 180K before for all the files because i added it
> into the server{} block and these location blocks were actually means the
> rate_limit 180k will apply to any flv,mp4,jpeg file and after adding -720
> before the location ~\.(mp4)$, the only 720p files will be served on
> limit_rate 500k and the rest would remain the same which is 180k in my case.

Good stuff -- each directive has a meaning, and if you wanted most
requests to have the 180 rate limit, then you put it in the right place.

Changing the "mp4" location to be "~ -720\.mp4$" means that those ones
will have the higher rate; but if you don't have a second location{}
for the other mp4s, they won't see the "mp4" directive, and so may not
be served correctly.

> I didn't used curl instead wget.

That's fine -- wget does a similar task to curl; and it's always good
to be able to demonstrate that the change you made fixed what was broken
(and didn't break what was already right).

Cheers,

  f
--
Francis Daly        francis@daoine.org
13731c628e20ffd83b6114ff2c406272?d=identicon&s=25 shahzaib mushtaq (shahzaib12)
on 2013-07-22 06:28
(Received via mailing list)
hello,

>Changing the "mp4" location to be "~ -720\.mp4$" means that those ones
>will have the higher rate; but if you don't have a second location{}
>for the other mp4s, they won't see the "mp4" directive, and so may not
>be served correctly.

Yes, i've created different block locations for mp4 files and every mp4
file is working fine, you can check the config below and let me know if
there's anything wrong you see ?

location ~ -720\.(mp4)$ {
                mp4;
                expires 7d;
                limit_rate 500k;
                root /var/www/html/videos;
                 valid_referers none blocked  domain.com;
                if ($invalid_referer) {
                    return   403;
                }
                }
location ~ -480\.(mp4)$ {
                mp4;
                expires 7d;
                limit_rate 250k;
                root /var/www/html/videos;
                 valid_referers none blocked  domain.com;
                if ($invalid_referer) {
                    return   403;
                }
                }
location ~ \.(mp4)$ {
                mp4;
                expires 7d;
                root /var/www/html/videos;
                 valid_referers none blocked  domain.com;
                if ($invalid_referer) {
                    return   403;
                }
                }
36a8284995fa0fb82e6aa2bede32adac?d=identicon&s=25 Francis Daly (Guest)
on 2013-07-22 21:29
(Received via mailing list)
On Mon, Jul 22, 2013 at 09:27:59AM +0500, shahzaib shahzaib wrote:

Hi there,

> location ~ -480\.(mp4)$ {
>                 mp4;
>                 expires 7d;
>                 root /var/www/html/videos;
>                  valid_referers none blocked  domain.com;
>                 if ($invalid_referer) {
>                     return   403;
>                 }
>                 }

It looks reasonable from here.

The various repeated directives may fit better one level higher, but
that depends on the rest of the configuration.

The parentheses ("()") around mp4 in the locations look unnecessary.

But if it does what you want, it's good.

  f
--
Francis Daly        francis@daoine.org
13731c628e20ffd83b6114ff2c406272?d=identicon&s=25 shahzaib mushtaq (shahzaib12)
on 2013-07-23 07:27
(Received via mailing list)
Going with the same configuration as far as they are working for me.

Thanks again Francis :)

Best Regards.
Shahzaib
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.