Robert Br
2006-Feb-08 22:41 UTC
[Rails] debugging 500 Internal Server Error when dispatch.fcgi run?
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/troubleshooting-ruby-on-rails.php , 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. -- Posted via http://www.ruby-forum.com/.
Jim Nachlin
2006-Feb-08 22:49 UTC
[Rails] debugging 500 Internal Server Error when dispatch.fcgi run?
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/troubleshooting-ruby-on-rails.php > , 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.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?
Robert Br
2006-Feb-08 23:52 UTC
[Rails] Re: debugging 500 Internal Server Error when dispatch.fcgi r
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 <controller not set>#<action not set> </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.<<</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>: {"/rails/performers/list?keywords"=>"rolling stones"}</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>: {"cookie"=>[], "Cache-Control"=>"no-cache"}<br/> </body> </html> ------------------------------------------------------------------------------- -- Posted via http://www.ruby-forum.com/.
Mark Wilden
2006-Feb-09 01:32 UTC
[Rails] debugging 500 Internal Server Error when dispatch.fcgirun?
> 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/troubleshooting-ruby-on-rails.php , >> I tried running dispatch.fcgi on the command line. When I run it, no >> matter where I run it, it outputs: >> >> 500 Internal Server ErrorYou''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.
Jim Nachlin
2006-Feb-09 16:42 UTC
[Rails] Re: debugging 500 Internal Server Error when dispatch.fcgi r
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_fastcgi.html#FastCgiServer 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 Robert Br wrote:> 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 > <controller not set>#<action not set> > </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.<<</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>: > {"/rails/performers/list?keywords"=>"rolling > stones"}</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>: {"cookie"=>[], > "Cache-Control"=>"no-cache"}<br/> > > > > </body> > </html> > ------------------------------------------------------------------------------- >
Guest
2006-Feb-13 20:33 UTC
[Rails] Re: Re: debugging 500 Internal Server Error when dispatch.fc
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] -- Posted via http://www.ruby-forum.com/.