部署 生产环境的部署问题

davidminaki · 2015年03月21日 · 最后由 davidminaki 回复于 2015年03月21日 · 4854 次阅读

参考 https://github.com/ruby-china/ruby-china/wiki/Ubuntu-14.04-%E4%B8%8A%E4%BD%BF%E7%94%A8-Nginx-Passenger-%E9%83%A8%E7%BD%B2-Ruby-on-Rails 在阿里云上部署了一个应用,结果总是报 这个错误

We're sorry, but something went wrong.

We've been notified about this issue and we'll take a look at it shortly.

nginx 的配置成开发环境正常

server {
    listen 80 default;
    server_name huwai78.com;
    root /home/david/huwai78/public;
    passenger_enabled on;
    #rails_env production;
    rails_env development;
}

能够正常访问,然后 baidu google 了半天没有找到合适的解决办法 就采用这种方式启动

rails s -e production

报错信息如下

=> Booting Puma
=> Rails 4.2.1 application starting in production on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/home/david/huwai78/app/models/user.rb:1:in `<top (required)>': superclass mismatch for class User (TypeError)
    from /home/david/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:360:in `require_or_load'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:317:in `depend_on'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:233:in `require_dependency'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:472:in `block (2 levels) in eager_load!'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:471:in `each'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:471:in `block in eager_load!'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:469:in `each'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:469:in `eager_load!'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:346:in `eager_load!'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/application/finisher.rb:56:in `each'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `run'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/david/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
    from /home/david/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /home/david/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
    from /home/david/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /home/david/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `each'
    from /home/david/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `call'
    from /home/david/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
    from /home/david/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
    from /home/david/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/application.rb:352:in `initialize!'
    from /home/david/huwai78/config/environment.rb:5:in `<top (required)>'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
    from /home/david/huwai78/config.ru:3:in `block in <main>'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `instance_eval'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `initialize'
    from /home/david/huwai78/config.ru:in `new'
    from /home/david/huwai78/config.ru:in `<main>'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `eval'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `new_from_string'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/rack-1.6.0/lib/rack/builder.rb:40:in `parse_file'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/rack-1.6.0/lib/rack/server.rb:299:in `build_app_and_options_from_config'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/rack-1.6.0/lib/rack/server.rb:208:in `app'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/commands/server.rb:61:in `app'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/rack-1.6.0/lib/rack/server.rb:336:in `wrapped_app'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/rack-1.6.0/lib/rack/server.rb:272:in `start'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/commands/server.rb:80:in `start'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:80:in `block in server'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /home/david/.rvm/gems/ruby-2.2.0/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'
/home/david/huwai78/app/models/user.rb:1:in `<top (required)>': superclass mismatch for class User (TypeError)

User 类继承了什么类?

#2 楼 @Rei class User < ActiveRecord::Base

server {
    listen 80 default;
    server_name huwai78.com;
    root /home/david/huwai78/public;
    passenger_enabled on;
    #rails_env production;
    rails_env development;
}

这种环境下能够正常运行

#3 楼 @davidminaki 因为不知道你的源码,只能问你有没有做过什么特别的事了,例如在 Rails 载入前执行了什么代码。

我贴一下生产环境的配置文件

#Rails.application.configure do
Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # Code is not reloaded between requests.
  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both thread web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = true

  # Enable Rack::Cache to put a simple HTTP cache in front of your application
  # Add `rack-cache` to your Gemfile before enabling this.
  # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
  # config.action_dispatch.rack_cache = true

  # Disable Rails's static asset server (Apache or nginx will already do this).
  #config.serve_static_files = false
  config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

  # Generate digests for assets URLs.
  config.assets.digest = true

  # Version of your assets, change this if you want to expire all your assets.
  config.assets.version = '1.0'

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # Set to :debug to see everything in the log.
  config.log_level = :debug

  # Prepend all log lines with the following tags.
  # config.log_tags = [ :subdomain, :uuid ]

  # Use a different logger for distributed setups.
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = "http://assets.example.com"

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  # config.action_mailer.raise_delivery_errors = false

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation can not be found).
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify

  # Disable automatic flushing of the log to improve performance.
  # config.autoflush_log = false

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false
end

#4 楼 @Rei

#6 楼 @davidminaki 你怎么不用 nginx 管理启动呀?

为什么 server 里面写成了 rails_env development;

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册