# File Upload Problems With Apache and Lighttpd But Not Webric

**URL:** <https://www.ruby-forum.com/t/file-upload-problems-with-apache-and-lighttpd-but-not-webric/52345>\
**Category:** Rails\
**Created:** [January 12, 2006, 11:53pm UTC](https://www.ruby-forum.com/t/file-upload-problems-with-apache-and-lighttpd-but-not-webric/52345 "2006-01-12T23:53:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HunterSs\_Lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6bbea6/32.png) [@HunterSs\_Lists](https://www.ruby-forum.com/u/HunterSs_Lists)\
**Post date:** [January 12, 2006, 11:53pm UTC](https://www.ruby-forum.com/t/file-upload-problems-with-apache-and-lighttpd-but-not-webric/52345/1 "2006-01-12T23:53:33Z")

</div>

I am having trouble uploading files through a form when using Apache  
(production) or Lighttpd (development). The odd thing is that when I  
force  
script/server to load Webrick, the upload works just fine on the same  
code-base.

When it fails, the upload just sits there forever. Some browsers  
eventually  
return an error code, others spin for a long time… Anyway, it never  
recovers.

The file is a 1.7MB SWF (Flash) file and we’re using File Column.

Since it happens on Apache and Lighttpd, I’m thinking either:

1. FCGI. Both of those server setups are using FCGI but Webrick is  
not… Is  
FCGI doing something bad?

2. MIME issues of some kind?? I dunno about this one but I’ve tried  
everything so I’m looking at strange stuff. Both have entries for SWF  
files  
in their MIME types though, so this shouldn’t be a problem, right?

Anyway, I’m on MacOS X 10.4.

Has anyone seen anything like this? Any help appreciated.

Cheers.

---

<div class="post-metadata">

**Author:** ![HunterSs\_Lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6bbea6/32.png) [@HunterSs\_Lists](https://www.ruby-forum.com/u/HunterSs_Lists)\
**Post date:** [January 13, 2006, 9:57am UTC](https://www.ruby-forum.com/t/file-upload-problems-with-apache-and-lighttpd-but-not-webric/52345/2 "2006-01-13T09:57:13Z")

</div>

Hunter’s Lists wrote:

> I am having trouble uploading files through a form when using Apache  
> (production) or Lighttpd (development). The odd thing is that when I  
> force script/server to load Webrick, the upload works just fine on the same  
> code-base.

> …

> Anyway, I’m on MacOS X 10.4.
> 
> Has anyone seen anything like this? Any help appreciated.

Are you uploading via Safari? Lighttpd requires the following to be  
added to your lighttpd.conf file for uploads via file\_column to work:

$HTTP[“useragent”] =~ “^(._MSIE._)|(._AppleWebKit._)$” {  
server.max-keep-alive-requests = 0  
}

This doesn’t explain the Apache troubles you’re experiencing though.  
Perhaps if you posted the error message you’re receiving it might help  
track it down. Also check the development.log file to see what’s going  
on when the browser hangs.

---

<div class="post-metadata">

**Author:** ![HunterSs\_Lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6bbea6/32.png) [@HunterSs\_Lists](https://www.ruby-forum.com/u/HunterSs_Lists)\
**Post date:** [January 13, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/file-upload-problems-with-apache-and-lighttpd-but-not-webric/52345/3 "2006-01-13T18:01:49Z")

</div>

Nick,

Thanks for getting back.

Yes, I am on Safari and your trick did solve the problem on Lighttpd -  
thanks!

Unfortunately, production is Apache so I still need to solve that issue.

When this happens on Apache, it just hangs there. The last thing in the  
log  
file is the rendering of the page that submits the file - nothing about  
the  
upload submission.

The browser error message depends on the browser. Safari says it lost a  
connection, IE just gives ‘Page Cannot Be Displayed’ though both  
browsers  
hang for a few minutes before they return the error.

If anyone could give me any tips as to what I could do to continue  
testing  
this, I’d really appreciate it.

Is there a keep alive setting for Apache similar to this Lighttpd  
setting  
that I should tweak?

Cheers,  
Hunter

---

<div class="post-metadata">

**Author:** ![HunterSs\_Lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6bbea6/32.png) [@HunterSs\_Lists](https://www.ruby-forum.com/u/HunterSs_Lists)\
**Post date:** [January 14, 2006, 1:13am UTC](https://www.ruby-forum.com/t/file-upload-problems-with-apache-and-lighttpd-but-not-webric/52345/4 "2006-01-14T01:13:37Z")

</div>

Hunter’s Lists wrote:

> Nick,
> 
> Thanks for getting back.
> 
> Yes, I am on Safari and your trick did solve the problem on Lighttpd -  
> thanks!

Pleased to hear it 🙂

> If anyone could give me any tips as to what I could do to continue  
> testing this, I’d really appreciate it.
> 
> Is there a keep alive setting for Apache similar to this Lighttpd  
> setting that I should tweak?

I did some digging, and found this very handy article by Scott L.  
about optimising Apache for use with Rails:

> **[Apache tuning for Rails and FastCGI :: scottstuff.net](https://scottstuff.net/blog/articles/2005/07/20/apache-tuning-for-rails-and-fastcgi/index.html)**
>
> There’s a surprisingly small amount of documentation out there on tuning Apache for optimum Rails performance. Almost everyone mentions the first step (use FastCGI, not regular CGI), but that’s such a huge performance boost that it’s really...

Here’s a quote - “By default, FastCGI assumes that your server will  
respond to queries within 30 seconds. I added the -idle-timeout 120  
parameter just so I can deal with really slow responses better.”

Here’s my guess:  
In your locally hosted environment the 1.7mb upload flies up well within  
the 30 seconds and the limit that FastCGI imposes isn’t a problem. When  
you switch to a remote hosted (I’m assuming?) production environment,  
the upload takes over 30seconds causing FastCGI to choke.

Try adding the following to your apache.conf file as Scott suggests,  
replacing /path/to/your with the correct path for your server  
environment:

FastCgiServer /path/to/your/dispatch.fcgi -idle-timeout 120   
-initial-env RAILS\_ENV=production -processes 2

This forces the timeout to a more sensible number and runs two FastCGI  
processes. (Try going a bit higher with the timeout value if things  
still aren’t happy.)

Good luck!
