【问题标题】:Debugging a rails app deployment to Dreamhost with fcgi使用 fcgi 调试 Rails 应用程序部署到 Dreamhost
【发布时间】:2014-10-26 04:33:16
【问题描述】:

我在共享的 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 gem,但事实并非如此:

$ 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'

关于如何调试它的任何想法? 谢谢

【问题讨论】:

  • 我刚刚遇到了这个问题,有什么解决办法吗?

标签: ruby-on-rails debugging dreamhost fastcgi


【解决方案1】:

我今天遇到了这个问题 - 很难理解 dispatch.fcgi 出了什么问题。浏览器中的“Rails 应用程序无法正常启动”和日志中的“脚本头过早结束: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

...然后,当您从应用程序加载页面时,您将获得描述性错误页面。这应该使您能够弄清楚实际问题是什么。

【讨论】:

    猜你喜欢
    • 2023-03-16
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2011-06-07
    • 2011-06-08
    • 2010-12-22
    • 2011-09-09
    相关资源
    最近更新 更多