dispatch.fcgi和rails for phusion

时间:2013-03-21 20:34:46

标签: ruby-on-rails passenger

我遇到以下问题: 在我的托管(www.site5.com)上,ruby很老 - 1.8.7,服务器在Apache下运行,Phusion Passenger用于部署。 支持团队安装了一个RVM,以便我可以使用ruby 1.9.3。然而,即使是最简单的rails应用程序,服务器也会报告

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

问题在于配置我在这里提供的dispatch.fcgi和.htaccess文件:

dispatch.fcgi

    #!/home/foo/.rvm/rubies/ruby-1.9.3-p392/bin/ruby
    ENV['RAILS_ENV'] ||= 'production'
    ENV['HOME'] ||= `echo ~`.strip
    ENV['GEM_HOME'] = File.expand_path('~/.rvm/gems/ruby-1.9.3-p392')
    ENV['GEM_PATH'] = File.expand_path('~/.rvm/gems/ruby-1.9.3-p392') + ":" +
        File.expand_path('~/.rvm/gems/ruby-1.9.3-p392@global')
    require 'fcgi' 
    require File.join(File.dirname(__FILE__), '../config/environment.rb')
    class Rack::PathInfoRewriter
     def initialize(app)
       @app = app
     end
     def call(env)
       env.delete('SCRIPT_NAME')
       parts = env['REQUEST_URI'].split('?')
       env['PATH_INFO'] = parts[0]
       env['QUERY_STRING'] = parts[1].to_s
       @app.call(env)
     end
    end
Rack::Handler::FastCGI.run  Rack::PathInfoRewriter.new(try::Application)

的.htaccess

AddHandler application/x-httpd-php52 .php
<IfModule mod_fastcgi.c>
AddHandler fastcgi-script .fcgi
</IfModule>
<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi
</IfModule>

Options +FollowSymLinks +ExecCGI 
#Change to your environment
RailsEnv production
RewriteEngine On
 RewriteCond %{REQUEST_URI} ^/stats/(.*)$ [OR]
 RewriteCond %{REQUEST_URI} ^/failed_auth.html$
 RewriteRule .* - [L]
 RewriteRule ^$ index.html [QSA]
 RewriteRule ^([^.]+)$ $1.html [QSA]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

支持团队努力,但到目前为止我们还没有找到出路......

1 个答案:

答案 0 :(得分:2)

检查您是否确实获得了运行dispatch.fcgi的ruby版本,例如添加

提高RUBY_VERSION

首先在文件中查看使用网络浏览器访问网站时产生的输出(希望在那里提供回溯,它们就在我的情况下。)

我刚刚在fsdata.se网站上与类似情况作斗争。即使像你这样的#!/ shebang行,该文件实际上是由ruby 1.8.7执行的!对此的解决方法是创建一个dispatch.fcgi,它只执行正确的ruby版本的exec执行真正的调度脚本,就像这样(修改为你的路径):

  

exec(“/ usr / bin / env /home/foo/.rvm/rubies/ruby-1.9.3-p392/bin/ruby / home / foo / [rails app的路径] / public / realdispatch。 FCGI“)

realdispatch.fcgi的内容与dispatch.fcgi类似。我从dreamhost得到了它,这是一个很好的资源页面。

我的.htaccess(由fsdata生成)看起来像这样:

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

现在,一切正常,除了我的资产网址没有正确加载 - 仍在处理那个。)