# Download Large Files Directly

**URL:** <https://www.ruby-forum.com/t/download-large-files-directly/205386>\
**Category:** NGINX\
**Created:** [April 5, 2011, 5:36pm UTC](https://www.ruby-forum.com/t/download-large-files-directly/205386 "2011-04-05T17:36:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [April 5, 2011, 5:36pm UTC](https://www.ruby-forum.com/t/download-large-files-directly/205386/1 "2011-04-05T17:36:33Z")

</div>

Hy @ All,

Is there an Option in nginx to set a limit for the download filesize, so  
that the requested file will be downloaded from the proxied server  
(apache) directly?

Example:

testfile.bin over 10 MB, will send directly to apache

Client --\> Apache

testfile.bin under 10 MB, will send to nginx cache and then to apache

Client --\> nginx Cache --\> Apache

Any Solutions?

Regards,

Maik U.

---

<div class="post-metadata">

**Author:** ![maikungeriok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@maikungeriok](https://www.ruby-forum.com/u/maikungeriok)\
**Post date:** [April 5, 2011, 6:19pm UTC](https://www.ruby-forum.com/t/download-large-files-directly/205386/2 "2011-04-05T18:19:03Z")

</div>

> Client → Apache
> 
> testfile.bin under 10 MB, will send to nginx cache and then to apache
> 
> Client → nginx Cache → Apache
> 
> Any Solutions?

You can implement the following solution:

- any request passes to the Apache
- probe the file size
- if size over 10MB - serve it like you want
- if under - send X-Accel-Redirect response to nginx

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

---

<div class="post-metadata">

**Author:** ![maikungeriok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@maikungeriok](https://www.ruby-forum.com/u/maikungeriok)\
**Post date:** [April 5, 2011, 7:56pm UTC](https://www.ruby-forum.com/t/download-large-files-directly/205386/3 "2011-04-05T19:56:00Z")

</div>

Alexander Kolesen wrote in post #991075:

> > Client → Apache
> > 
> > testfile.bin under 10 MB, will send to nginx cache and then to apache
> > 
> > Client → nginx Cache → Apache
> > 
> > Any Solutions?
> 
> You can implement the following solution:
> 
> - any request passes to the Apache
> - probe the file size
> - if size over 10MB - serve it like you want
> - if under - send X-Accel-Redirect response to nginx
> 
> [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/XSendfile)

Let me explain this with a other way:

if the file has a size over 10 MB then nginx will not cache the file in  
the filesystem and it will downloaded directly from the apache

if the file has a size under 10 MB then nginx will cache the file in the  
filesystem
