# Nginx limit\_rate based on file extension

**URL:** <https://www.ruby-forum.com/t/nginx-limit-rate-based-on-file-extension/244847>\
**Category:** NGINX\
**Created:** [June 24, 2016, 9:10am UTC](https://www.ruby-forum.com/t/nginx-limit-rate-based-on-file-extension/244847 "2016-06-24T09:10:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [June 24, 2016, 9:10am UTC](https://www.ruby-forum.com/t/nginx-limit-rate-based-on-file-extension/244847/1 "2016-06-24T09:10:39Z")

</div>

Hello,

I wonder is there any way to limit\_rate based on file extension in  
Nginx,  
for example, putting different rate limit rules on flv and mp4?

I’ve tried this, but somehow returned file not found

location ~\* .(flv|f4v)$ {  
limit\_rate\_after 1m;  
limit\_rate 80k;  
}

location ~\* .(mp4|m4v)$ {  
limit\_rate\_after 3m;  
limit\_rate 80k;  
}

Your help is really appreciate!

Posted at Nginx Forum:

> **[Nginx limit\_rate based on file extension](https://forum.nginx.org/read.php?2,267852,267852#msg-267852)**
>
> Hello, I wonder is there any way to limit\_rate based on file extension in Nginx, for example, putting different rate limit rules on flv and mp4? I've tried this, but somehow returned file not found location ~\* \\.(flv|f4v)$ { limit\_rate\_after

---

<div class="post-metadata">

**Author:** ![charles13](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/0ea827/32.png) [@charles13](https://www.ruby-forum.com/u/charles13)\
**Post date:** [June 25, 2016, 2:39am UTC](https://www.ruby-forum.com/t/nginx-limit-rate-based-on-file-extension/244847/2 "2016-06-25T02:39:13Z")

</div>

On Fri, Jun 24, 2016 at 03:10:08AM -0400, charles13 wrote:

Hi there,

> I wonder is there any way to limit\_rate based on file extension in Nginx,  
> for example, putting different rate limit rules on flv and mp4?

I’ve not tested it, but it should Just Work.

limit\_rate can work in location{}, so put it in the location{} that  
handles the urls that you care about.

> I’ve tried this, but somehow returned file not found
> 
> location ~\* .(flv|f4v)$ {  
> limit\_rate\_after 1m;  
> limit\_rate 80k;  
> }

One request is handled in one location. Only the config in, or inherited  
into, that location counts.

What is “root” set to here? What file on your filesystem do you want  
nginx to return?

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
