Premature end of script headers; dispatch.cgi - ok

Hi,

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).

First app is accessible at: http://mydomain.com/cwps and it all works.
Second app is accessible at: http://mydomain.com/robo and the index
works, but http://mydomain.com/robo/controller/action bombs with
“Rails application failed to start properly”.

  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]

I basically copied the cwps Directory node and I modified the pen port
number (to my second pen which is servicing robo).

What else can I check?

Thanks,
Tiberiu

Hi

  1. First of all give permission 775 for the whole application

  2. see that the ownership of that file is proper

  3. Open dispatch.cgi and check the path for ruby that might be wrong.

If all 3 things above is correct then i guess it should work…

Thanks

Dhaval P.
Software Engineer

sales(AT)railshouse(DOT)com

Hi Dhaval,

  1. I did a chmod -R 775 on the whole directory
  2. dispatch.cgi has been created by admin - there is no other user on
    the system (except mongrel and pen)
  3. dispatch.cgi has the correct ruby path

What’s more puzzling is that the permissions, the files and the setup
are almost identical to the application that is working. Permissions
are exactly the same and all the dispatch files have been copied
directly from the application that is working.
I thought this was going to be an easy task - I guess not…

Thanks,
Tiberiu

I don’t know what the hell happened to my reply. Anyway, I tried all
of these and still nothing.

Thanks,
Tiberiu

Hi Dhaval,

Thanks for the reply. If I start script/console I don’t get any
errors. I also don’t have any models to really test my code with, but
I do have a helper that prints “hello world” and that works.

This is the exact error that is displayed when you access the simple
controller action blah/foo:
Application error
Rails application failed to start properly

This is what is logged:
[Fri Jun 20 11:00:48 2008] [error] [client XX.XXX.XX.XXX] Premature
end of script headers: dispatch.cgi

This is what is in the access log:
XX.XXX.XX.XXX - - [20/Jun/2008:11:00:48 -0700] “GET /robo/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”

Thanks,
Tiberiu

Hi,

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”

Thanks,
Tiberiu

Mr_Tibs wrote:

I don’t know what the hell happened to my reply. Anyway, I tried all
of these and still nothing.

Thanks,
Tiberiu

Hi

Do let me know wat error u get in script/console and apache log…Then I
can do the needful.

thanks

Dhaval P.
Software Engineer
Ruby on Rails

sales(AT)railshouse(DOT)com

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!

Tiberiu

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.

Tiberiu