# Premature end of script headers: dispatch.cgi

**URL:** <https://www.ruby-forum.com/t/premature-end-of-script-headers-dispatch-cgi/55546>\
**Category:** Rails\
**Created:** [March 22, 2006, 1:05am UTC](https://www.ruby-forum.com/t/premature-end-of-script-headers-dispatch-cgi/55546 "2006-03-22T01:05:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@Nas](https://www.ruby-forum.com/u/Nas)\
**Post date:** [March 22, 2006, 1:05am UTC](https://www.ruby-forum.com/t/premature-end-of-script-headers-dispatch-cgi/55546/1 "2006-03-22T01:05:19Z")

</div>

Hi

I am running ruby 1.8.4 and rails 1.0.0 with Apache 2. I made a simple  
rails application called demo and also created a controller called say  
and an action called hello which is working fine using webrick. To run  
it under Apache I created a symlink demo1 which is linked to the  
demo/public directory. If I run it using [www.example.com/demo1](http://www.example.com/demo1) then I  
get the “Rails- Welcome Aboard” page. However, the problem starts when I  
try to access [www.example.com/demo1/say/hello](http://www.example.com/demo1/say/hello). It gives, “Application  
error  
Rails application failed to start properly” When I do a tail -f  
error\_log then I get “Premature end of script headers: dispatch.cgi”.  
Since I spent almost a day trying to work out the problem and visiting  
several forums where most of the people advise on checking the  
permission of log files and shebang in dispatch.cgi which I already  
checked but now I am not sure what is wrong.

I would be really grateful if you could tell me what I might be doing  
wrong.

Please let me know if you want to have a look at my dispatch.cgi or any  
other file.

Thanks a lot in advance.

---

<div class="post-metadata">

**Author:** ![Nas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@Nas](https://www.ruby-forum.com/u/Nas)\
**Post date:** [March 22, 2006, 1:29am UTC](https://www.ruby-forum.com/t/premature-end-of-script-headers-dispatch-cgi/55546/2 "2006-03-22T01:29:54Z")

</div>

Try to run dispatch.cgi from the command line.

Also, make sure it’s executable.

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![Nas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@Nas](https://www.ruby-forum.com/u/Nas)\
**Post date:** [March 22, 2006, 8:42am UTC](https://www.ruby-forum.com/t/premature-end-of-script-headers-dispatch-cgi/55546/3 "2006-03-22T08:42:51Z")

</div>

Hi Tom,

Thanks for the reply. I tried running it from the command line  
(./dispatch.cgi) and I get a “500 internal Server Error”

Any ideas why I am getting this?

Thanks

Tom M. wrote:

> Try to run dispatch.cgi from the command line.
> 
> Also, make sure it’s executable.
> 
> –  
> – Tom M.

---

<div class="post-metadata">

**Author:** ![Nas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@Nas](https://www.ruby-forum.com/u/Nas)\
**Post date:** [March 22, 2006, 9:44am UTC](https://www.ruby-forum.com/t/premature-end-of-script-headers-dispatch-cgi/55546/4 "2006-03-22T09:44:19Z")

</div>

On Mar 21, 2006, at 11:42 PM, Nas wrote:

> Thanks for the reply. I tried running it from the command line  
> (./dispatch.cgi) and I get a “500 internal Server Error”
> 
> Any ideas why I am getting this?

That’s actually a good sign(!)

In my experience, that means everything is basically OK,  
and the error is generated because there is no request  
on STDIN (when you run it via the command line).

1. Is it really dispatch.cgi or is it dispatch.fcgi?
2. This may have to do with web server config, since  
it appears (in a rather twisted fashion) that all  
else is OK.

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![Nas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@Nas](https://www.ruby-forum.com/u/Nas)\
**Post date:** [March 22, 2006, 10:26am UTC](https://www.ruby-forum.com/t/premature-end-of-script-headers-dispatch-cgi/55546/5 "2006-03-22T10:26:48Z")

</div>

Tom M. wrote:

> On Mar 21, 2006, at 11:42 PM, Nas wrote:
> 
> > Thanks for the reply. I tried running it from the command line  
> > (./dispatch.cgi) and I get a “500 internal Server Error”
> > 
> > Any ideas why I am getting this?
> 
> That’s actually a good sign(!)
> 
> In my experience, that means everything is basically OK,  
> and the error is generated because there is no request  
> on STDIN (when you run it via the command line).
> 
> 1. Is it really dispatch.cgi or is it dispatch.fcgi?
> 2. This may have to do with web server config, since  
> it appears (in a rather twisted fashion) that all  
> else is OK.
> 
> –  
> – Tom M.

Yes, it is dispatch.cgi, so what might be wrong with the server config?

I have copied a portion of my config file below, please let me know if  
you find something wrong in there.

\<VirtualHost \*\*\*\*\*\*\*\*\*\*_:80\>  
ServerName **:80  
ServerAlias www.**_  
UseCanonicalName Off  
ServerAdmin "**_@_.com"  
DocumentRoot /var/www/vhosts/ **_** /httpdocs  
CustomLog /var/www/vhosts/ **_** /statistics/logs/access\_log  
ErrorLog /var/www/vhosts/**\*\*\*/statistics/logs/error\_log

```
    ScriptAlias /cgi-bin/ /var/www/vhosts/ ******* /cgi-bin/
    <IfModule mod_ssl.c>
            SSLEngine off
    </IfModule>
    <Directory /var/www/vhosts/ ******* /httpdocs>
    <IfModule mod_perl.c>
    <Files ~ (\.pl$)>
            SetHandler perl-script
                                                                                                   PerlHandler 

```

ModPerl::Registry  
Options ExecCGI  
allow from all  
PerlSendHeader On  
  
  
  
php\_admin\_flag engine on  
php\_admin\_value open\_basedir  
“/var/www/vhosts/_ **/httpdocs:/tmp"** _  
   
   
_**php\_admin\_flag engine on  
php\_admin\_value open\_basedir  
"/var/www/vhosts/**__/httpdocs:/tmp"_  
   
   
_\<Files ~ (.py$)\>  
SetHandler python-program  
PythonHandler mod\_python.cgihandler_  
   
   
   
_\<Directory /var/www/vhosts/_\*\*\*\*\*\*/httpdocs/demo/public/\>  
Options ExecCGI FollowSymLinks  
AddHandler cgi-script .cgi  
AllowOverride all  
Allow from all  
Order allow,deny  
  
\<Directory /var/www/vhosts/ **/web\_users\>**  
   
**AddType text/plain .php .php4 .php3 .phtml  
php\_admin\_flag engine off**  
   
   
**AddType text/plain .php .php5 .php4 .php3 .phtml  
php\_admin\_flag engine off**  
   
   
**Alias “/error\_docs” "/var/www/vhosts/** /error\_docs”  
ErrorDocument 400 /error\_docs/bad\_request.html  
ErrorDocument 401 /error\_docs/unauthorized.html  
ErrorDocument 403 /error\_docs/forbidden.html  
ErrorDocument 404 /error\_docs/not\_found.html  
ErrorDocument 500 /error\_docs/internal\_server\_error.html  
AddType application/x-httpd-eruby .rhtml

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Nas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@Nas](https://www.ruby-forum.com/u/Nas)\
**Post date:** [March 22, 2006, 12:16pm UTC](https://www.ruby-forum.com/t/premature-end-of-script-headers-dispatch-cgi/55546/6 "2006-03-22T12:16:39Z")

</div>

Tom M. wrote:

> I know _nothing_ about Rail via CGI on Apache.
> 
> One thing I notice right away, however, is that  
> there doesn’t appear to be anything in your config  
> that would direct Rails URLs to dispatch.cgi…
> 
> –  
> – Tom M.

Any idea, how can I do that?

---

<div class="post-metadata">

**Author:** ![Nas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@Nas](https://www.ruby-forum.com/u/Nas)\
**Post date:** [March 22, 2006, 11:18am UTC](https://www.ruby-forum.com/t/premature-end-of-script-headers-dispatch-cgi/55546/7 "2006-03-22T11:18:49Z")

</div>

I know _nothing_ about Rail via CGI on Apache.

One thing I notice right away, however, is that  
there doesn’t appear to be anything in your config  
that would direct Rails URLs to dispatch.cgi…

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![Nas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@Nas](https://www.ruby-forum.com/u/Nas)\
**Post date:** [March 23, 2006, 4:36pm UTC](https://www.ruby-forum.com/t/premature-end-of-script-headers-dispatch-cgi/55546/8 "2006-03-23T16:36:57Z")

</div>

Nas wrote:

> Tom M. wrote:
> 
> > I know _nothing_ about Rail via CGI on Apache.
> > 
> > One thing I notice right away, however, is that  
> > there doesn’t appear to be anything in your config  
> > that would direct Rails URLs to dispatch.cgi…
> > 
> > –  
> > – Tom M.
> 
> Any idea, how can I do that?

Now I am using fcgi and its working fine. I think thats the reason  
people advise to use fast cgi.

Anyway, thanks for your replies Tom.

Nas
