# Limit serving to responses only below certain size

**URL:** <https://www.ruby-forum.com/t/limit-serving-to-responses-only-below-certain-size/227178>\
**Category:** NGINX\
**Created:** [March 6, 2013, 2:28pm UTC](https://www.ruby-forum.com/t/limit-serving-to-responses-only-below-certain-size/227178 "2013-03-06T14:28:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Calin\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@Calin\_D](https://www.ruby-forum.com/u/Calin_D)\
**Post date:** [March 6, 2013, 2:28pm UTC](https://www.ruby-forum.com/t/limit-serving-to-responses-only-below-certain-size/227178/1 "2013-03-06T14:28:41Z")

</div>

Hi,

Is there a way to server files only below a certain size?  
eg. Return 403 on files bigger than 5MB?

---

<div class="post-metadata">

**Author:** ![Calin\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@Calin\_D](https://www.ruby-forum.com/u/Calin_D)\
**Post date:** [March 6, 2013, 4:30pm UTC](https://www.ruby-forum.com/t/limit-serving-to-responses-only-below-certain-size/227178/2 "2013-03-06T16:30:51Z")

</div>

On 6 March 2013 13:28, Calin D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> Is there a way to server files only below a certain size?  
> eg. Return 403 on files bigger than 5MB?

Assuming you’re talking about local filesystem files, you might try to  
proxy\_pass back round to yourself, and do an if() based on  
$upstream\_http\_content\_length.

If you’re already proxy’ing, you could use the same technique but  
without the double nginx hit.

I’d personally look at /how/ too-large files are getting onto disk,  
and fix that, however.

## Jonathan

Jonathan M. // Oxford, London, UK

> **[Jonathan Matthews :: Words Typed, Great Rates For Cash](https://www.jpluscplusm.com)**

---

<div class="post-metadata">

**Author:** ![Calin\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@Calin\_D](https://www.ruby-forum.com/u/Calin_D)\
**Post date:** [March 6, 2013, 8:28pm UTC](https://www.ruby-forum.com/t/limit-serving-to-responses-only-below-certain-size/227178/3 "2013-03-06T20:28:41Z")

</div>

Unfortunately the way big files are getting there is beyond my control.

On Wed, Mar 6, 2013 at 5:30 PM, Jonathan M.

---

<div class="post-metadata">

**Author:** ![Calin\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@Calin\_D](https://www.ruby-forum.com/u/Calin_D)\
**Post date:** [March 6, 2013, 9:07pm UTC](https://www.ruby-forum.com/t/limit-serving-to-responses-only-below-certain-size/227178/4 "2013-03-06T21:07:50Z")

</div>

Are you saying that you do not have administrative control of your  
system?

Jonathan is right - set policies that disallow large file sizes and  
enforce  
them.

If necessary use chron to check for large files and remove them.
