<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Zeke (He)</title>
    <link>https://ruby-china.org/Zeke</link>
    <description/>
    <language>en-us</language>
    <item>
      <title>阿里云 nginx+pasenger+rails+capistrano 部署成功，但页面访问报错</title>
      <description>&lt;p&gt;1.基本情况&lt;/p&gt;

&lt;p&gt;按照 gorails 中的最新教程配置部署，&lt;a href="https://gorails.com/deploy/ubuntu/18.04#nginx-passenger" rel="nofollow" target="_blank"&gt;https://gorails.com/deploy/ubuntu/18.04#nginx-passenger&lt;/a&gt;
服务器：阿里云 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!”页面&lt;/p&gt;

&lt;p&gt;2.问题&lt;/p&gt;

&lt;p&gt;通过 ip 访问服务器，页面显示如下错误——“We're sorry, but something went wrong.
The issue has been logged for investigation. Please try again later.”
&lt;img src="https://l.ruby-china.com/photo/2019/a9d136b2-51a7-4727-8917-3f2cf9ec19e1.png!large" title="" alt=""&gt;&lt;/p&gt;

&lt;p&gt;3.诉求&lt;/p&gt;

&lt;p&gt;希望知道从何入手排错，让 ip 访问能出来 rails 页面。&lt;/p&gt;

&lt;p&gt;4.passenger 和 nginx 都正常启动&lt;/p&gt;

&lt;p&gt;5.nginx/error.log日志如下&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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 &amp;lt;module:Finisher&amp;gt;'
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 `&amp;lt;top (required)&amp;gt;'
App 6137 output:     config.ru:3:in `require_relative'
App 6137 output:     config.ru:3:in `block in &amp;lt;main&amp;gt;'
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 `&amp;lt;main&amp;gt;'
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 &amp;lt;module:App&amp;gt;'
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 `&amp;lt;module:App&amp;gt;'
App 6137 output:     /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `&amp;lt;module:PhusionPassenger&amp;gt;'
App 6137 output:     /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `&amp;lt;main&amp;gt;'
[ 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', '~&amp;gt; 5.2.2'
# Use postgresql as the database for Active Record
gem 'pg'
# Use Puma as the app server
gem 'puma', '~&amp;gt; 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~&amp;gt; 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '&amp;gt;= 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', '~&amp;gt; 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~&amp;gt; 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~&amp;gt; 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~&amp;gt; 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~&amp;gt; 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~&amp;gt; 4.8'

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

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '&amp;gt;= 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', '&amp;gt;= 3.3.0'
  gem 'listen', '&amp;gt;= 3.0.5', '&amp;lt; 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', '~&amp;gt; 2.0.0'
end

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

gem 'capistrano', '~&amp;gt; 3.11'
gem 'capistrano-rails', '~&amp;gt; 1.4'
gem 'capistrano-passenger', '~&amp;gt; 0.2.0'
gem 'capistrano-rbenv', '~&amp;gt; 2.1', '&amp;gt;= 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: &amp;amp;default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: &amp;lt;%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %&amp;gt;

development:
  &amp;lt;&amp;lt;: *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:
  &amp;lt;&amp;lt;: *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: &amp;lt;%= ENV['DATABASE_URL'] %&amp;gt;
#
production:
  &amp;lt;&amp;lt;: *default
  database: sunapp_production
  username: deploy
  password: 123456
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;进展：&lt;/p&gt;

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

&lt;p&gt;/home/deploy/myapp/.rbenv-vars
nano .rbenv-vars&lt;/p&gt;

&lt;p&gt;现在出来这个页面了
&lt;img src="https://l.ruby-china.com/photo/2019/ed0ce0dc-7008-42a3-8625-257048a662d4.png!large" title="" alt=""&gt;&lt;/p&gt;</description>
      <author>Zeke</author>
      <pubDate>Fri, 22 Mar 2019 19:45:16 +0800</pubDate>
      <link>https://ruby-china.org/topics/38277</link>
      <guid>https://ruby-china.org/topics/38277</guid>
    </item>
  </channel>
</rss>
