新手问题 阿里云 nginx+pasenger+rails+capistrano 部署成功,但页面访问报错

Zeke · 2019年03月22日 · 最后由 Zeke 回复于 2019年03月23日 · 2661 次阅读

1.基本情况

按照 gorails 中的最新教程配置部署,https://gorails.com/deploy/ubuntu/18.04#nginx-passenger 服务器:阿里云 ubuntu18.04,nginx + passenger + rails5.2.2 + ruby2.6.1,postgresql 客户端:Mac,ruby2.6.1 + rails5.2.2 + postgresql ,用 capistrano 部署成功,没有报错。客户端本地能访问“Yay! You’re on Rails!”页面

2.问题

通过 ip 访问服务器,页面显示如下错误——“We're sorry, but something went wrong. The issue has been logged for investigation. Please try again later.”

3.诉求

希望知道从何入手排错,让 ip 访问能出来 rails 页面。

4.passenger 和 nginx 都正常启动

5.nginx/error.log日志如下

deploy@rails-server-02:~$ sudo less /var/log/nginx/error.log
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:291:in `block in require'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:257:in `load_dependency'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:291:in `require'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:378:in `block in require_or_load'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:37:in `block in load_interlock'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies/interlock.rb:13:in `loading'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:37:in `load_interlock'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:356:in `require_or_load'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/active_support.rb:48:in `block in require_or_load'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/active_support.rb:47:in `require_or_load'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:334:in `depend_on'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/active_support.rb:82:in `depend_on'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:246:in `require_dependency'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/engine.rb:478:in `block (2 levels) in eager_load!'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/engine.rb:477:in `each'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/engine.rb:477:in `block in eager_load!'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/engine.rb:475:in `each'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/engine.rb:475:in `eager_load!'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/engine.rb:356:in `eager_load!'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/application/finisher.rb:69:in `each'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/initializable.rb:32:in `instance_exec'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/initializable.rb:32:in `run'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
App 6137 output:     /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
App 6137 output:     /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
App 6137 output:     /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
App 6137 output:     /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
App 6137 output:     /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/tsort.rb:347:in `each'
App 6137 output:     /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/tsort.rb:347:in `call'
App 6137 output:     /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
App 6137 output:     /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
App 6137 output:     /home/deploy/.rbenv/versions/2.6.1/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/
App 6137 output: initializable.rb:60:in `run_initializers'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/application.rb:361:in `initialize!'
App 6137 output:     /home/deploy/sunapp/releases/20190322110922/config/environment.rb:5:in `<top (required)>'
App 6137 output:     config.ru:3:in `require_relative'
App 6137 output:     config.ru:3:in `block in <main>'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/builder.rb:55:in `instance_eval'
App 6137 output:     /home/deploy/sunapp/shared/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/builder.rb:55:in `initialize'
App 6137 output:     config.ru:1:in `new'
App 6137 output:     config.ru:1:in `<main>'
App 6137 output:     /usr/share/passenger/helper-scripts/rack-preloader.rb:101:in `eval'
App 6137 output:     /usr/share/passenger/helper-scripts/rack-preloader.rb:101:in `preload_app'
App 6137 output:     /usr/share/passenger/helper-scripts/rack-preloader.rb:189:in `block in <module:App>'
App 6137 output:     /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:380:in `run_block_and_record_step_progress'
App 6137 output:     /usr/share/passenger/helper-scripts/rack-preloader.rb:188:in `<module:App>'
App 6137 output:     /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
App 6137 output:     /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>'
[ E 2019-03-22 19:35:29.0967 5713/Tm age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /home/deploy/sunapp/current: The application encountered the following error: ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)
  Error ID: 39d94ccc
  Error details saved to: /tmp/passenger-error-H9rG5G.html

[ E 2019-03-22 19:35:29.1032 5713/T9 age/Cor/Con/CheckoutSession.cpp:276 ]: [Client 1-3] Cannot checkout session because a spawning error occurred. The identifier of the error is 39d94ccc. Please see earlier logs for details about the error.
(END)


6.Gemfile:  

source 'https://gems.ruby-china.com'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.1'
gem 'bundler', '1.17.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.2'
# Use postgresql as the database for Active Record
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of chromedriver to run system tests with Chrome
  gem 'chromedriver-helper'
end

gem 'capistrano', '~> 3.11'
gem 'capistrano-rails', '~> 1.4'
gem 'capistrano-passenger', '~> 0.2.0'
gem 'capistrano-rbenv', '~> 2.1', '>= 2.1.4'

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]


7.database.yml

# PostgreSQL. Versions 9.1 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On OS X with Homebrew:
#   gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
#   gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: sunapp_development

  # The specified database role being used to connect to postgres.
  # To create additional roles in postgres see `$ createuser --help`.
  # When left blank, postgres will use the default role. This is
  # the same name as the operating system user that initialized the database.
  username: zeke

  # The password associated with the postgres role (username).
  # password:

  # Connect on a TCP socket. Omitted by default since the client uses a
  # domain socket that doesn't need configuration. Windows does not have
  # domain sockets, so uncomment these lines.
  #host: localhost

  # The TCP port the server listens on. Defaults to 5432.
  # If your server runs on a different port number, change accordingly.
  #port: 5432

  # Schema search path. The server defaults to $user,public
  #schema_search_path: myapp,sharedapp,public

  # Minimum log levels, in increasing order:
  #   debug5, debug4, debug3, debug2, debug1,
  #   log, notice, warning, error, fatal, and panic
  # Defaults to warning.
  #min_messages: notice

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.

test:
  <<: *default
  database: sunapp_test

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
#   DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
#   production:
#     url: <%= ENV['DATABASE_URL'] %>
#
production:
  <<: *default
  database: sunapp_production
  username: deploy
  password: 123456

进展:

服务器端/.rbenv-vars 中的 SECRET_KEY_BASE 配置错了,我放上的是教程里的,后来看了下视频,原来是要开发机生成再粘贴到服务端。 方法是:在 mac 下的 sunapp 下执行 bundle exec rails secret

/home/deploy/myapp/.rbenv-vars nano .rbenv-vars

现在出来这个页面了

1 楼 已删除

排版太乱了,我觉得还是 nginx 的问题

gwq 回复

谢谢回复,重新排了下版。 目前正在学习《ruby on rails 教程》第四版,按照 gorails 教程重装几次了,其间遇到的问题都有抓手,可以搜索解决。但是这次的错误无从下手。

按照日志末尾的提示“Error details saved to: /tmp/passenger-error-H9rG5G.html”,我打开了也没得到什么有用的信息。 在没用 capistrano 部署的时候,ip 访问服务器,页面有 nginx 提示。 现在应该从哪开始行动?

你可以谷歌哈 rails passenger ActiveSupport::MessageEncryptor::InvalidMessage

有没有正确配置 /etc/nginx/passenger.conf 下 ruby 路径,

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini; 
passenger_ruby /home/xxxx/.rbenv/shims/ruby;
dccmmtop 回复

谢谢,现在有了进展。

gwq 回复

谢谢,现再有进展了。

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