# Nginx proxy truncates large file downloads to 1.1G

**URL:** <https://www.ruby-forum.com/t/nginx-proxy-truncates-large-file-downloads-to-1-1g/200134>\
**Category:** NGINX\
**Created:** [December 6, 2010, 2:22am UTC](https://www.ruby-forum.com/t/nginx-proxy-truncates-large-file-downloads-to-1-1g/200134 "2010-12-06T02:22:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [December 6, 2010, 2:22am UTC](https://www.ruby-forum.com/t/nginx-proxy-truncates-large-file-downloads-to-1-1g/200134/1 "2010-12-06T02:22:23Z")

</div>

Hello All:

So nginx so far has been running great. Today however I discovered that  
when downloading a file larger than 1G (ie 1.5G) it will always fail  
leaving the client with a file of 1.1G and an incomplete download. If I  
point directly to the webserver the download completes properly.  
Downloading over a slow or local or fast link does not change the  
problem. Its the file size that appears to be causing the issue. Any  
size of file download which is under 1G works and downloads with no  
issues.

I suspect its some issue with proxy buffering however I have not been  
able to come up with the secret sauce to make it work. Below is the  
last iteration of my config which still truncates large file downloads.  
The boxes that nginx is running on are a dedicated dual core dual Xeon  
3Ghz with 8G of ram.

Also there does not seem to be anything in the error logs when this  
occurs.

Regards,  
Duane

The files  
user nginx;  
worker\_processes 4;  
events {  
worker\_connections 1024;  
use epoll;  
multi\_accept on;  
}

http { #http  
include mime.types;  
default\_type application/octet-stream;  
gzip on;  
gzip\_http\_version 1.0;  
gzip\_comp\_level 2;  
gzip\_proxied any;  
gzip\_types text/plain text/css application/x-javascript  
text/xml application/xml application/xml+rss text/javascript;  
gzip\_buffers 16 8k;  
#disable for IE 6  
gzip\_disable “MSIE [1-6].(?!.\*SV1)”;

# POST size limit

```
# Set File upload limit at 2G
client_max_body_size 2000M;
sendfile on;
keepalive_timeout 65;

```

server { #server80  
listen 192.168.1.231:80 ;  
server\_name [x.x.com](http://x.x.com);

##Blocked IP address message  
error\_page 403 = [http://x.y.com/monitor/x\_403.html](http://x.y.com/monitor/x_403.html);

```
 ### Add SSL specific settings here ###
    keepalive_timeout 240;
    access_log /nginx/cust-SSL/logs/access.log;
    error_log /nginx/cust-SSL/logs/error.log;

location /nginx_status {
      stub_status on;
      access_log off;
      allow 1.1.1.0.0/24;

      deny all;
    }

```

##FILE DOWNLOAD OPTIONS --this is the bit that is not working.  
location /path\_for\_testing {  
##hosts to allow  
proxy\_buffering on;  
#proxy\_buffer\_size 16k;  
proxy\_buffer\_size 64k;  
proxy\_buffers 64 64k;  
proxy\_set\_header X-Forwarded-Host $host;  
proxy\_set\_header X-Forwarded-Server $host;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_pass [http://x.y.com:80/path\_for\_testing](http://x.y.com:80/path_for_testing);  
proxy\_redirect off;  
}

##FIX CONTENT

location /different\_path {  
subs\_filter\_types text/html text/css text/xml;  
#subs\_filter [http://x.x.com/sf/](http://x.x.com/sf/) [http://x.x.com/sf/](http://x.x.com/sf/) i;  
subs\_filter [http://x.x.com/svn/](http://x.x.com/svn/) [http://x.x.com/svn/](http://x.x.com/svn/) i;  
proxy\_set\_header X-Forwarded-Host $host;  
proxy\_set\_header X-Forwarded-Server $host;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_pass [http://x.x.com:80/different\_path/](http://x.x.com:80/different_path/);  
proxy\_redirect off;  
}

## Proxy the rest of the site, temporarily commented out as I am

debugging the in the path for testing section.

location / {  
#proxy\_buffering on;  
#proxy\_buffer\_size 16k;  
#proxy\_buffers 32 16k;  
#client\_body\_buffer\_size 128k;  
#proxy\_busy\_buffers\_size 64k;  
proxy\_set\_header X-Forwarded-Host $host;  
proxy\_set\_header X-Forwarded-Server $host;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_pass [http://x.x.com:80/](http://x.x.com:80/);  
proxy\_redirect off;  
}

---

<div class="post-metadata">

**Author:** ![dmorin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dmorin](https://www.ruby-forum.com/u/dmorin)\
**Post date:** [December 6, 2010, 2:33am UTC](https://www.ruby-forum.com/t/nginx-proxy-truncates-large-file-downloads-to-1-1g/200134/2 "2010-12-06T02:33:01Z")

</div>

On Sun, Dec 5, 2010 at 5:21 PM, Duane M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> So nginx so far has been running great. Today however I discovered that  
> when downloading a file larger than 1G (ie 1.5G) it will always fail  
> leaving the client with a file of 1.1G and an incomplete download. If I  
> point directly to the webserver the download completes properly.  
> Downloading over a slow or local or fast link does not change the  
> problem. Its the file size that appears to be causing the issue. Any  
> size of file download which is under 1G works and downloads with no issues.

I have to ask - you’ve tried this on multiple client machines? You’re  
sure it’s not the local browser/browser cache/local disk space/temp  
space/etc? 🙂 Sometimes the small things are to blame

(also server swap space, server temp space [in case it needed to keep  
it on disk somewhere temporarily, etc, etc])

Just my two cents if you’re waiting for a response and haven’t checked  
those silly things out (“why is my server acting up?” and later you  
realize you’re out of disk space, that’s why…)

---

<div class="post-metadata">

**Author:** ![dmorin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dmorin](https://www.ruby-forum.com/u/dmorin)\
**Post date:** [September 14, 2011, 8:57am UTC](https://www.ruby-forum.com/t/nginx-proxy-truncates-large-file-downloads-to-1-1g/200134/3 "2011-09-14T08:57:28Z")

</div>

Even i am facing the same problem but i m yet to figure out the exact  
cause of it…The disk space seems to be fine…In my case when  
downloading a file larger than 1G(1.2 GB) it will truncate to 1 GB…

---

<div class="post-metadata">

**Author:** ![dmorin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dmorin](https://www.ruby-forum.com/u/dmorin)\
**Post date:** [September 14, 2011, 9:41am UTC](https://www.ruby-forum.com/t/nginx-proxy-truncates-large-file-downloads-to-1-1g/200134/4 "2011-09-14T09:41:00Z")

</div>

On Sun, 2010-12-05 at 20:21 -0500, Duane M. wrote:

> So nginx so far has been running great. Today however I discovered that  
> when downloading a file larger than 1G (ie 1.5G) it will always fail  
> leaving the client with a file of 1.1G and an incomplete download.

Try disabling gzip and see if that helps. If so, tuning the gzip  
settings might be in order.

Cliff

---

<div class="post-metadata">

**Author:** ![dmorin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dmorin](https://www.ruby-forum.com/u/dmorin)\
**Post date:** [September 14, 2011, 9:53am UTC](https://www.ruby-forum.com/t/nginx-proxy-truncates-large-file-downloads-to-1-1g/200134/5 "2011-09-14T09:53:59Z")

</div>

Hello!

On Wed, Sep 14, 2011 at 08:57:28AM +0200, JAZZ F. wrote:

> Even i am facing the same problem but i m yet to figure out the exact  
> cause of it…The disk space seems to be fine…In my case when  
> downloading a file larger than 1G(1.2 GB) it will truncate to 1 GB…

proxy\_max\_temp\_file\_size, when reached, causes relative long delay  
in reading from upstream server; this may cause timeout on  
upstream server, seen as “truncation”.

There are 3 possible workarounds:

1. Use smaller proxy\_max\_temp\_file\_size to reduce delay in  
reading.

2. Use larger proxy\_max\_temp\_file\_size to avoid hitting it.

3. Use larger timeout on upstream server.

Maxim D.
