# File Upload fails for large files

**URL:** <https://www.ruby-forum.com/t/file-upload-fails-for-large-files/153689>\
**Category:** Rails\
**Created:** [November 20, 2008, 6:00am UTC](https://www.ruby-forum.com/t/file-upload-fails-for-large-files/153689 "2008-11-20T06:00:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chirantan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@chirantan](https://www.ruby-forum.com/u/chirantan)\
**Post date:** [November 20, 2008, 6:00am UTC](https://www.ruby-forum.com/t/file-upload-fails-for-large-files/153689/1 "2008-11-20T06:00:17Z")

</div>

Hi,

I am using mongrel with nginx and I am facing problem when I try to  
upload a large file. After googling about this, I came to know that I  
need to configure nginx.conf file by setting ‘client\_max\_body\_size’ to  
a value of desired maximum file size. I did that but still it does not  
seem to work. Files above 200 KB do not get uploaded. I also get a  
weird error about sockets (Given below the nginx.conf file)

What am I doing wrong? Please help.

My nginx.conf lokos like this:

user postgres ;  
worker\_processes 2;

error\_log /var/www/webapps/FileSharing/log/error.log notice;  
pid /var/www/webapps/FileSharing/log/nginx.pid;

events {  
worker\_connections 1024;  
}

http {  
include mime.types;  
default\_type application/octet-stream;

```
# no sendfile on OSX uncomment
#this if your on linux or bsd
#sendfile on;
tcp_nopush on;

keepalive_timeout 65;
tcp_nodelay on;

upstream mongrel {
    server 127.0.0.1:4000;
    server 127.0.0.1:4001;
    server 127.0.0.1:4002;
}

gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;

server {
    listen 80;
    server_name v-ibm35.persistent.co.in;
    access_log /var/www/webapps/FileSharing/log/access.log;
    error_log /var/www/webapps/FileSharing/log/error.log;
    root /var/www/webapps/FileSharing/public;
    access_log on;
    rewrite_log on;

```

#client\_max\_body\_size 1048576k;  
client\_max\_body\_size 1024M;  
client\_body\_buffer\_size 512k;  
client\_header\_buffer\_size 1048576k;

```
    location /ui
   {
      root /var/www/webapps/FileSharing/public;
    }

    location ~ ^/$ {
      if (-f /index.html){
        rewrite (.*) /index.html last;
      }
       proxy_pass http://mongrel;
    }

    location / {
      if (!-f $request_filename.html) {
        proxy_pass http://mongrel;
      }
      rewrite (.*) $1.html last;
    }

    location ~ .html {
       root /Users/ez/nginx/public;
    }

    location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|

```

doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)$ {  
access\_log off;  
expires 30d;  
}

```
  location / {

     # needed to forward user's IP address to rails
     proxy_set_header X-Real-IP $remote_addr;

     # needed for HTTPS
    #proxy_set_header X_FORWARDED_PROTO https;
    #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect false;
    #proxy_max_temp_file_size 1048576k;
    proxy_max_temp_file_size 1024M;

    # If the file exists as a static file serve it directly

```

without  
# running all the other rewite tests on it  
if (-f $request\_filename) {  
break;  
}

```
   # this is the meat of the rails page caching config
   # it adds .html to the end of the url and then checks
   # the filesystem for that file. If it exists, then we
   # rewite the url to have explicit .html on the end
   # and then send it on its way to the next config rule.
   # if there is no file on the fs then it sets all the
   # necessary headers and proxies to our upstream mongrels
   if (-f $request_filename.html) {
    rewrite (.*) $1.html break;
  }

  if (!-f $request_filename) {
    proxy_pass http://mongrel;
    break;
  }
 error_page 500 502 503 504 /500.html;
location = /500.html {
  root /var/www/webapps/FileSharing/public;
}

}

}

```

}

Thu Nov 20 10:47:37 +0530 2008: Error reading HTTP body:  
#\<RuntimeError: Socket read returned insufficient data: 5672\>  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel/  
http\_request.rb:107:in `read_socket' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/ http_request.rb:77:in`read\_body’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel/  
http\_request.rb:55:in `initialize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb: 149:in`new’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel.rb:  
149:in `process_client' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb: 285:in`run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel.rb:  
285:in `initialize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb: 285:in`new’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel.rb:  
285:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb: 268:in`initialize’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel.rb:  
268:in `new' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb: 268:in`run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel/  
configurator.rb:282:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/ configurator.rb:281:in`each’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel/  
configurator.rb:281:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails: 128:in`run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel/  
command.rb:212:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281 /usr/local/bin/mongrel_rails:19:in`load’  
/usr/local/bin/mongrel\_rails:19
