使用fcgi调试rails应用程序部署到Dreamhost

时间:2014-09-02 00:51:26

标签: ruby-on-rails debugging dreamhost fastcgi

我在共享的dreamhost服务器上安装了ruby 2.1.2和rails 4.1.5。我成功地设法通过跟随this guide部署了一个带有fcgi的裸机应用程序。然后我尝试使用capistrano 3部署我之前开发的应用程序。cap production deploy工作正常,rails console production也是如此。

问题在于,每当我尝试转到我的应用程序的URL时,我都会收到500错误,这只会说“Rails应用程序无法正常启动”。我尝试按this other guide进行故障排除,但我没有走得太远。

据我所知,我的public / dispatch.fcgi文件似乎工作正常:

#!/home/myuser/.ruby/bin/ruby

ENV['RAILS_ENV'] = 'production'
ENV['HOME'] ||= `echo ~`.strip
ENV['GEM_HOME'] = File.expand_path('~/.gems')
ENV['GEM_PATH'] = File.expand_path('~/.gems')

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(MyApp::Application)

我尝试运行文件本身,我只得到一个没有错误的提示(这似乎暗示应用程序没问题)。

我的log / production.log文件为空。我的服务器日志只显示几条带有帮助消息[Mon Sep 01 17:45:14 2014] [error] [client 201.246.73.121] Premature end of script headers: dispatch.fcgi的行,这至少告诉我正在调用dispatch.fcgi。谷歌搜索只告诉我,我可能会错过fcgi宝石,但事实并非如此:

$ bundle show fcgi
/home/myuser/.gems/gems/fcgi-0.9.2.1

以防万一,这是我的Gemfile,不包括测试和生产环境:

source 'https://rubygems.org'
ruby '2.1.2'
gem 'therubyracer'
gem 'fcgi'
gem 'mysql'
gem 'rails', '4.1.2'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0',          group: :doc
gem 'spring',        group: :development
gem 'bootstrap-sass'
gem 'high_voltage'
gem 'slim-rails'
gem 'savon', '~> 2.5.1'
gem 'spreadsheet', '~> 0.9.7'

有关如何调试此问题的任何想法? 感谢

1 个答案:

答案 0 :(得分:2)

我今天遇到了这个问题 - 很难理解dispatch.fcgi出了什么问题。 " Rails应用程序无法正常启动后,错误被掩盖了#34;在您的浏览器和"脚本标题的过早结束:dispatch.fcgi"在你的日志中。

如果你在dispatch.fcgi中使用这一行:

Rack::Handler::FastCGI.run Rack::PathInfoRewriter.new(MyApp::Application)

...并将其替换为以下行:

wrappedApp = Rack::Builder.new do
  use Rack::ShowExceptions
  use Rack::PathInfoRewriter
  run MyApp::Application
end
Rack::Handler::FastCGI.run wrappedApp

...当您从应用加载页面时,您将获得描述性错误页面。这可以让你弄清楚实际问题是什么。