3

我对 Rails 应用程序比较陌生,但我有一个在本地工作的 Rails 应用程序,我正试图将其部署到 DreamHost 上的共享托管服务器。我已经关注了所有 wiki 和 stackoverflow 的问题,但我仍然没有找到答案。

我正在使用 Capistrano 进行部署,并且我已经解决了所有问题以使部署成功。但是,当我访问站点上非静态资源的任何内容时,我会收到“内部服务器错误”以及来自乘客的此错误:

Internal server error
Passenger encountered the following error:
The application spawner server exited unexpectedly: Unexpected end-of-file detected.

Exception class:
PhusionPassenger::Rack::ApplicationSpawner::Error
Backtrace:
#   File    Line    Location
0   /dh/passenger/lib/phusion_passenger/rack/application_spawner.rb 134 in `start'
1   /dh/passenger/lib/phusion_passenger/spawn_manager.rb    253 in `spawn_rack_application'
2   /dh/passenger/lib/phusion_passenger/abstract_server_collection.rb   132 in `lookup_or_add'
3   /dh/passenger/lib/phusion_passenger/spawn_manager.rb    246 in `spawn_rack_application'
4   /dh/passenger/lib/phusion_passenger/abstract_server_collection.rb   82  in `synchronize'
5   /dh/passenger/lib/phusion_passenger/abstract_server_collection.rb   79  in `synchronize'
6   /dh/passenger/lib/phusion_passenger/spawn_manager.rb    244 in `spawn_rack_application'
7   /dh/passenger/lib/phusion_passenger/spawn_manager.rb    137 in `spawn_application'
8   /dh/passenger/lib/phusion_passenger/spawn_manager.rb    275 in `handle_spawn_application'
9   /dh/passenger/lib/phusion_passenger/abstract_server.rb  357 in `__send__'
10  /dh/passenger/lib/phusion_passenger/abstract_server.rb  357 in `server_main_loop'
11  /dh/passenger/lib/phusion_passenger/abstract_server.rb  206 in `start_synchronously'
12  /dh/passenger/helper-scripts/passenger-spawn-server 99  

我可以通过 SSH 连接到服务器并手动运行“rails s”以使服务器在 3000 端口上运行,并且一切正常。

这是我的环境.rb:

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
LoLItemDb::Application.initialize!

# potential fix for Dreamhost shared resources
# from: http://stackoverflow.com/a/3214748/189292
require 'rubygems'
require 'rubygems/gem_runner'
ENV['GEM_PATH'] = '/home/gravitydev/ruby/gems:/usr/lib/ruby/gems/1.8'
Gem.clear_paths

部署.rb:

user = "XXXXXXXXX"
domain = "XXXXXXXXX.com"
database = "mysql.XXXXXXXXX.com"

set :application, "XXXXXXXXX"
set :rails_env, "production"
set :use_sudo, false

# set rake to be verbose for capistrano
# http://stackoverflow.com/questions/7071126/how-can-i-run-rake-with-trace-within-capistrano
set :rake, "#{rake} --trace"

# here we set a custom paths to commands since on Dreamhost
# servers the user path is a bit different
set :bundle_cmd, "/home/#{user}/.gems/bin/bundle"
require 'bundler/capistrano'

# redirect path for whenever, and use bundler to execute it
set :whenever_command, "/home/#{user}/.gems/bin/bundle exec whenever"
require 'whenever/capistrano'

# configure credentials
set :user, user
set :password, "XXXXXXXXX"

# configure git
default_run_options[:pty] = true                          # Must be set for the password prompt
                                                          # from git to work
set :repository, "git@github.com:XXXXXXXXX/XXXXXXXXX.git"  # Your clone URL
set :deploy_to, "/home/#{user}/#{domain}"
set :scm, "git"
set :scm_passphrase, "XXXXXXXXX"                    # The deploy user's password
set :scm_verbose, true
set :git_shallow_clone, 1

# configure deploy location
set :deploy_to, "/home/#{user}/#{domain}"

# setup web server
server domain, :app, :web, :db, :primary => true
#server domain, :app, :web
#role :db, database, :primary => true

# for SSH
# see: http://wiki.dreamhost.com/Capistrano
set :chmod755, "app config db lib public vendor script script/* public/disp*"

# if you want to clean up old releases on each deploy uncomment this:
after "deploy:restart", "deploy:cleanup"

# run the all "LoL" tasks to refresh the database
#after "deploy:restart", "lol:all"

# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts

# for Passenger
namespace :deploy do
  task :restart do
    run "touch #{current_path}/tmp/restart.txt"
  end
end

和 GEMFILE:来源 'https://rubygems.org'

gem 'rails', '3.2.6'
gem 'bundler'
gem 'rake'
gem 'sqlite3'
gem 'haml'
gem 'nokogiri'
gem 'json'
gem 'whenever'
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
gem 'mysql2'
gem 'rack'
gem 'RedCloth', '4.2.9'
gem 'jquery-rails'
gem 'capistrano'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

大多数帖子似乎表明 gems 的路径不正确,但我已经通过搜索 Google 和 Dreamhost 的文档找到了所有配置更改。任何帮助是极大的赞赏!

4

2 回答 2

4

在搞砸了很长一段时间后,有几件事让我找到了解决方案。首先,在部署到 Dreamhost 时,您需要像这样覆盖 config.ru 中的 GEM_HOME 路径:

# taken from https://discussion.dreamhost.com/thread-128599.html
ENV['GEM_HOME'] = '/home/USERNAME/.gems'
require 'rubygems'
Gem.clear_paths

此外,我阅读了 abhas 的评论,这让我认为我Gemfile需要我不需要指定的宝石。基本上,我之前添加了它们来尝试模仿我的本地 gem 安装,但发现我并不需要它们。我的最终Gemfile看起来像这样:

source 'https://rubygems.org'

gem 'rails', '3.2.6'
gem 'bundler'
gem 'rake'
gem 'sqlite3'
gem 'haml'
gem 'nokogiri'
gem 'whenever'
gem 'mysql'
gem 'mysql2'
gem 'jquery-rails'
gem 'capistrano'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

进行这些更改后,Passenger 很高兴并找到了所有需要的宝石!感谢 abhas 让我考虑在正确的领域做出改变。

编辑:当 StackOverflow 允许我时,我会接受这个答案:)

于 2012-07-08T19:22:25.347 回答
1

在你的 gemfile 中改变这个

gem 'RedCloth', :require => 'redcloth'

它可能会起作用

于 2012-07-07T12:45:00.733 回答