Forum: Ruby on Rails debugging 500 Internal Server Error when dispatch.fcgi run?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E252a566c8abb53bcbfa1e64ebe1b9d4?d=identicon&s=25 Robert Br (robertakit)
on 2006-02-08 23:41
I'm trying to get my Ruby on Rails application to work under Apache.  It
works fine when run as WEBrick ("ruby script/server").

As suggested in
http://www.ocssolutions.com/support/ruby/troublesh...
, I tried running dispatch.fcgi on the command line.  When I run it, no
matter where I run it, it outputs:

500 Internal Server Error

Both the #! (shebang) line and the config/database.yml file are correct.

I tried comparing the output of "ruby --debug dispatch.fcgi" and "ruby
--debug script/server".  They look extremely similar except one says
"500 Internal Server Error" and the other says "Rails application
started on http://0.0.0.0:3000".  Since I'm using Linux (Fedora 3,
actually), I also tried "strace ruby --debug" and nothing unusual
happens by the time the "500 Internal Server Error" message is emitting;
it doesn't even look like it's trying to connect to the database.

Is there a way to get a more detailed trace of what dispatch.fcgi is
doing?  Is there a better way to debug this problem?

Thanks.
516b2dd693ce525d3f401b2ee1bef694?d=identicon&s=25 Jim Nachlin (Guest)
on 2006-02-08 23:49
(Received via mailing list)
Robert Br wrote:
> Both the #! (shebang) line and the config/database.yml file are correct.
My app is working, but I also get that error.  I think you always get
that error when runing the dispatch.fcgi from the command line, but if
you get errors that libraries are not found, then you have a different
problem.

> Is there a way to get a more detailed trace of what dispatch.fcgi is
> doing?  Is there a better way to debug this problem?

I have also wished for this.

As others have said, try deleting your /tmp/ruby_sess* files, and
restarting the httpd.

Which fcgi method are you using, and what do your relevant config files
and your dispatch.fcgi look like?
E252a566c8abb53bcbfa1e64ebe1b9d4?d=identicon&s=25 Robert Br (robertakit)
on 2006-02-09 00:52
Jim Nachlin wrote:
> Robert Br wrote:
>> Both the #! (shebang) line and the config/database.yml file are correct.
> My app is working, but I also get that error.  I think you always get
> that error when runing the dispatch.fcgi from the command line, but if
> you get errors that libraries are not found, then you have a different
> problem.

I discovered this as well.  But, I tried running it on the command line
again, setting environment variables as described in
http://docs.rinet.ru:8080/CP7/ch13.htm .  My reply is continued below.

>> Is there a way to get a more detailed trace of what dispatch.fcgi is
>> doing?  Is there a better way to debug this problem?
>
> I have also wished for this.
>
> As others have said, try deleting your /tmp/ruby_sess* files, and
> restarting the httpd.
>
> Which fcgi method are you using, and what do your relevant config files
> and your dispatch.fcgi look like?

Below are the configuration I added to httpd.conf ("rails.conf"),
fastcgi.conf (in the /etc/httpd/conf.d directory), dispatch.fcgi, and
.htaccess .  Also below is the output from running dispatch.fcgi on
command line after setting:

REQUEST_METHOD=GET
QUERY_STRING='/rails/performers/list?keywords=rolling+stones'

I'm not sure if these environment variables are accurate or not -- I
don't know what actually is passed to dispatch.fcgi via the .htaccess
file (via "dispatch.fcgi?$1").  I also tried running dispatch.cgi and
the results are identical.

Thanks for any further help.

----------------------------------rails.conf----------------------------------
#Alias /rails/ "/usr/lib/ruby/gems/1.8/gems/rails-1.0.0/html/"
Alias /rails/ "/usr/lib/ruby/gems/1.8/gems/rails-1.0.0/public/"
<Directory "/usr/lib/ruby/gems/1.8/gems/rails-1.0.0/public/">
    Options ExecCGI FollowSymLinks
    AllowOverride all
    Allow from all
    Order allow,deny
</Directory>
------------------------------------------------------------------------------

---------------------------------fastcgi.conf---------------------------------
LoadModule fastcgi_module modules/mod_fastcgi.so
<IfModule mod_fastcgi.c>
    FastCgiIpcDir /tmp/fcgi_ipc/
    AddHandler fastcgi-script .fcgi
</IfModule>
------------------------------------------------------------------------------

--------------------------------dispatch.fcgi---------------------------------
#!/usr/bin/ruby
require File.dirname(__FILE__) + "/../config/environment"
require 'fcgi_handler'

RailsFCGIHandler.process!
------------------------------------------------------------------------------

--------------------------------.htaccess-------------------------------------
# General Apache options
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI

# If you don't want Rails to look in certain directories,
# use the following rewrite rules so that Apache won't rewrite certain
requests
#
# Example:
#   RewriteCond %{REQUEST_URI} ^/notrails.*
#   RewriteRule .* - [L]

# Redirect all requests not available on the filesystem to Rails
# By default the cgi dispatcher is used which is very slow
#
# For better performance replace the dispatcher with the fastcgi one
#
# Example:
#   RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteEngine On

# If your Rails application is accessed via an Alias directive,
# then you MUST also set the RewriteBase in this htaccess file.
#
# Example:

Alias /performers
/usr/lib/ruby/gems/1.8/gems/rails-1.0.0/app/views/performers
RewriteBase /performers

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.rhtml [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /dispatch.fcgi?$1 [QSA,L]

# In case Rails experiences terminal errors
# Instead of displaying this message you can supply a file here which
will be rendered instead
#
# Example:
#   ErrorDocument 500 /500.html

ErrorDocument 500 "<h2>Application error</h2>Rails application failed to
start properly"
-------------------------------------------------------------------------------

-------------------------------dispatch.fcgi.out-------------------------------
Content-Type: text/html
Set-Cookie: _session_id=ee5040fdcaaa7ea5fb8ac35b22c2fb65; path=/
Status: 500 Internal Error
Cache-Control: no-cache

<html>
<head>
  <title>Action Controller: Exception caught</title>
  <style>
    body { background-color: #fff; color: #333; }

    body, p, ol, ul, td {
      font-family: verdana, arial, helvetica, sans-serif;
      font-size:   13px;
      line-height: 18px;
    }

    pre {
      background-color: #eee;
      padding: 10px;
      font-size: 11px;
    }

    a { color: #000; }
    a:visited { color: #666; }
    a:hover { color: #fff; background-color:#000; }
  </style>
</head>
<body>

<h1>
  NoMethodError in
  &lt;controller not set&gt;#&lt;action not set&gt;
</h1>
<pre>You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.&lt;&lt;</pre>



<p><code>RAILS_ROOT: public/../config/..</code></p>

<div id="traces">

    <a href="#"
onclick="document.getElementById('Framework-Trace').style.display='none';document.getElementById('Full-Trace').style.display='none';document.getElementById('Application-Trace').style.display='block';;
return false;">Application Trace</a> |

    <a href="#"
onclick="document.getElementById('Application-Trace').style.display='none';document.getElementById('Full-Trace').style.display='none';document.getElementById('Framework-Trace').style.display='block';;
return false;">Framework Trace</a> |

    <a href="#"
onclick="document.getElementById('Application-Trace').style.display='none';document.getElementById('Framework-Trace').style.display='none';document.getElementById('Full-Trace').style.display='block';;
return false;">Full Trace</a>

      <div id="Application-Trace" style="display: block;">
      <pre><code>/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/request.rb:143:in
`request_uri'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/request.rb:161:in
`path'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:453:in
`recognize!'
./public/../config/../lib/dispatcher.rb:38:in `dispatch'
./public/../config/../lib/fcgi_handler.rb:141:in `process_request'
./public/../config/../lib/fcgi_handler.rb:53:in `process!'
./public/../config/../lib/fcgi_handler.rb:52:in `each_cgi'
./public/../config/../lib/fcgi_handler.rb:52:in `process!'
./public/../config/../lib/fcgi_handler.rb:22:in `process!'</code></pre>
    </div>
      <div id="Framework-Trace" style="display: none;">
      <pre><code>/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/request.rb:143:in
`request_uri'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/request.rb:161:in
`path'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:453:in
`recognize!'
./public/../config/../lib/dispatcher.rb:38:in `dispatch'
./public/dispatch.fcgi:24</code></pre>
    </div>
      <div id="Full-Trace" style="display: none;">
      <pre><code>/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/request.rb:143:in
`request_uri'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/request.rb:161:in
`path'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:453:in
`recognize!'
./public/../config/../lib/dispatcher.rb:38:in `dispatch'
./public/../config/../lib/fcgi_handler.rb:141:in `process_request'
./public/../config/../lib/fcgi_handler.rb:53:in `process!'
./public/../config/../lib/fcgi_handler.rb:52:in `each_cgi'
./public/../config/../lib/fcgi_handler.rb:52:in `process!'
./public/../config/../lib/fcgi_handler.rb:22:in `process!'
./public/dispatch.fcgi:24</code></pre>
    </div>
  </div>







<h2 style="margin-top: 30px">Request</h2>
<p><b>Parameters</b>:
{&quot;/rails/performers/list?keywords&quot;=&gt;&quot;rolling
stones&quot;}</p>

<p><a href="#"
onclick="document.getElementById('session_dump').style.display='block';
return false;">Show session dump</a></p>
<div id="session_dump" style="display:none"><pre class='debug_dump'>---
{}</pre></div>


<h2 style="margin-top: 30px">Response</h2>
<b>Headers</b>: {&quot;cookie&quot;=&gt;[],
 &quot;Cache-Control&quot;=&gt;&quot;no-cache&quot;}<br/>



</body>
</html>
-------------------------------------------------------------------------------
48641c4be1fbe167929fb16c9fd94990?d=identicon&s=25 Mark Wilden (Guest)
on 2006-02-09 02:32
(Received via mailing list)
> Robert Br wrote:
>> I'm trying to get my Ruby on Rails application to work under Apache.  It
>> works fine when run as WEBrick ("ruby script/server").
>>
>> As suggested in
>> http://www.ocssolutions.com/support/ruby/troublesh... ,
>> I tried running dispatch.fcgi on the command line.  When I run it, no
>> matter where I run it, it outputs:
>>
>> 500 Internal Server Error

You'll find the answer in your Apache log file. On TextDrive, I had to
turn
on logging to get this, but after that, it was all clear.
516b2dd693ce525d3f401b2ee1bef694?d=identicon&s=25 Jim Nachlin (Guest)
on 2006-02-09 17:43
(Received via mailing list)
Robert,
The error message you are getting is from your rails app, suggesting
that it is being called.  I would look for an error in your appname/log
directory, in the logfile for whatever mode you are running in.

Also, this may not be necessary, but you could try specifying
FastCgiServer in your httpd.conf or fcgi.conf (this can not go in a
virtual host directive):
FastCgiServer "/path/to/app/public/dispatch.fcgi" -idle-timeout 20
-processes 1
FastCgiConfig -maxClassProcesses 2 -maxProcesses 2 -minProcesses 1
-processSlack 1

see:
http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcg...

Also, when you run it under Apache, is there anything in the httpd log
that suggests that the request is not coming in as you expect?
      - Jim
E252a566c8abb53bcbfa1e64ebe1b9d4?d=identicon&s=25 Guest (Guest)
on 2006-02-13 21:33
The problem was .htaccess.  I turned on "LogLevel debug" in the
httpd.conf file, but it wasn't particularly useful, except for point #1
below.  Here's what I did.

1) According to the log file, "Alias" doesn't work in .htaccess.  Don't
know why the sample .htaccess deceptively mentions this.
2) Added
   RewriteBase /rails/
   to .htaccess.  This seems necessary because otherwise the accessed
path is the full /usr/lib/ruby/... path, which is not a valid URL.
3) Did two things:
   a) Created a symlink "app" in public directory which points to the
actually Ruby on Rails ruby scripts.
   b) In .htaccess, changed
      RewriteRule ^(.*)$ dispatch.fcgi?$1 [QSA,L}
      to
      RewriteRule ^(.*)$ dispatch.fcgi?app/views/$1 [QSA,L]
4) Left this in .htaccess
   RewriteRule ^([^.]+)$ $1.rhtml [QSA,L]
This topic is locked and can not be replied to.