File Upload fails for large files

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’
a value of desired maximum file size. I did that but still it does
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/;
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 {
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
server {
listen 80;
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|
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_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
# running all the other rewite tests on it
if (-f $request_filename) {
# 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;
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>
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’
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’
149:in process_client' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/ mongrel.rb: 285:in run’
285:in initialize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/ mongrel.rb: 285:in new’
285:in run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/ mongrel.rb: 268:in initialize’
268:in new' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/ mongrel.rb: 268:in run’
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’
configurator.rb:281:in run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails: 128:in run’
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’

Its fixed.

We were using a Javascript to submit the form that held the file
field. When we used a submit button instead of the javascript, it all
started working properly. I wonder whats wrong internally but for now,
the code is working :-). If you are doing something similar, make sure
you use a submit button instead of a Javascript that submits the form.


If you are doing something similar, make sure
you use a submit button instead of a Javascript that submits the form.

Chirantan, look into the responds_to_parent plugin to do it via JS.

Oh great. Thanks for this Mark. :slight_smile: