I'm getting the dreaded "Premature end of script headers:
dispatch.cgi" message on my production server. Before I list all the
things that I tried, let me mention that I already have a Rails app
working on this server (installed by somebody else).
1. Tried running dispatch.cgi from the command line, and I get a 404
page: Action Controller: Exception caught ... NOT a 500 error, meaning
that dispatch.cgi (and the ruby path) is working correctly.
2. The permissions on the dispatch files are ok:
-rwxrwxr-x 1 admin psacln 479 Jun 18 19:50 dispatch.cgi
-rwxrwxr-x 1 admin psacln 861 Jun 18 19:50 dispatch.fcgi
-rwxrwxr-x 1 admin psacln 479 Jun 18 19:50 dispatch.rb
3. The permissions on the symbolic link in the httpdocs directory to
the capistrano folder is also ok.
4. I'm using apache, pen and mongrel_cluster. Pen and mongrel_cluster
are running ok. The apache config I'm not too sure about:
<Directory /var/www/vhosts/mydomain/httpdocs/robo>
Options +FollowSymLinks
# Let apache correctly rewrite the redirect
ProxyPassReverse http://localhost:8091/
RewriteEngine On
# If the cached page does not exist, send to mongrel
# RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://localhost:8091/$1 [P,QSA,L]
</Directory>
I basically copied the cwps Directory node and I modified the pen port
number (to my second pen which is servicing robo).
I think I keep clicking "Reply to author". Anyway, here's what I said
in my message:
1. script/console does not display errors when started, but I don't
really have any models to test it with
2. Application error Rails application failed to start properly -
printed when trying to access controller/action
3. in error_log:
[Fri Jun 20 11:00:48 2008] [error] [client XX.XXX.XX.XXX] Premature
end of script headers: dispatch.cgi
4. in access_log:
XX.XXX.XX.XXX - - [20/Jun/2008:11:00:48 -0700] "GET /robot/foo/blah
HTTP/1.1" 500 259 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:
1.8.1.6) Gecko/20071008 Ubuntu/7.10 (gutsy) Firefox/2.0.0.6"
I'm going CRAZY over this thing: I went back and I did a chmod 755 on
dispatch.cgi by mistake (not 775 as you specified). All of a sudden it
started working. I did a chmod 775 on dispatch.cgi and it stopped
working. I repeated this a few times and I thought it was all over -
the culprit being chmod 755. Then, I deployed a new release, and the
chmod trick stopped working. I kept rolling back and deploying new
releases a few times and the chmod sometimes does the trick, sometimes
it doesn't!!! Why God? Why?
Anyway - on a different note, the application is started in
development mode, even though the mongrel cluster config file
specifies "release". Also, with the other application that is
successfully working, I don't need to chmod anything and it starts in
production mode as expected.
AHAHAHAHA! THE RAGE!
There is a .htaccess HIDDEN file created in the public directory. That
file has to be removed. It cost me almost 8 hours of debugging!