为什么我被告知“缺少`secret_key_base`为'生产'”,即使我在我的config / secrets.yml文件中对其进行了硬编码?

时间:2017-04-10 15:13:50

标签: ruby-on-rails config ruby-on-rails-5 production secret-key

我在Ubuntu 14.04上使用Rails 5和Unicorn以及Nginx。我在读取我的SECRET_KEY_BASE环境变量时遇到了问题,因此我决定对其进行硬编码以使得工作正常(来自我的config / secrets.yml)文件)...

# Be sure to restart your server when you modify this file.

# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!

# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.

# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.

development:
  secret_key_base: devsecretkey

test:
  secret_key_base: testsecretkey

# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
  secret_key_base: secretkeybase
  #secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

但是当我尝试访问我的应用程序时,我会得到以下错误(来自我的/home/rails/myproject/shared/log/unicorn.stderr.log文件)

E, [2017-04-10T11:06:11.270645 #1249] ERROR -- : app error: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml` (RuntimeError)
E, [2017-04-10T11:06:11.270782 #1249] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/application.rb:513:in `validate_secret_key_config!'
E, [2017-04-10T11:06:11.270809 #1249] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/application.rb:246:in `env_config'
E, [2017-04-10T11:06:11.270827 #1249] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/engine.rb:693:in `build_request'
E, [2017-04-10T11:06:11.270842 #1249] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/application.rb:521:in `build_request'
E, [2017-04-10T11:06:11.270857 #1249] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/engine.rb:521:in `call'
E, [2017-04-10T11:06:11.270872 #1249] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/unicorn-5.2.0/lib/unicorn/http_server.rb:562:in `process_client'
E, [2017-04-10T11:06:11.270888 #1249] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/unicorn-5.2.0/lib/unicorn/http_server.rb:658:in `worker_loop'
E, [2017-04-10T11:06:11.270902 #1249] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/unicorn-5.2.0/lib/unicorn/http_server.rb:508:in `spawn_missing_workers'
E, [2017-04-10T11:06:11.270925 #1249] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/unicorn-5.2.0/lib/unicorn/http_server.rb:132:in `start'
E, [2017-04-10T11:06:11.270940 #1249] ERROR -- : /home/rails/.gem/ruby/2.4.0/gems/unicorn-5.2.0/bin/unicorn:126:in `<top (required)>'
E, [2017-04-10T11:06:11.270955 #1249] ERROR -- : /home/rails/.gem/ruby/2.4.0/bin/unicorn:22:in `load'
E, [2017-04-10T11:06:11.270969 #1249] ERROR -- : /home/rails/.gem/ruby/2.4.0/bin/unicorn:22:in `<top (required)>'
E, [2017-04-10T11:06:11.270985 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `load'
E, [2017-04-10T11:06:11.271013 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `kernel_load'
E, [2017-04-10T11:06:11.271030 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:27:in `run'
E, [2017-04-10T11:06:11.271044 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/cli.rb:332:in `exec'
E, [2017-04-10T11:06:11.271057 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
E, [2017-04-10T11:06:11.271071 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
E, [2017-04-10T11:06:11.271084 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
E, [2017-04-10T11:06:11.271098 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/cli.rb:20:in `dispatch'
E, [2017-04-10T11:06:11.271112 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
E, [2017-04-10T11:06:11.271125 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/cli.rb:11:in `start'
E, [2017-04-10T11:06:11.271143 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/exe/bundle:34:in `block in <top (required)>'
E, [2017-04-10T11:06:11.271157 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/lib/bundler/friendly_errors.rb:100:in `with_friendly_errors'
E, [2017-04-10T11:06:11.271171 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/gems/bundler-1.13.7/exe/bundle:26:in `<top (required)>'
E, [2017-04-10T11:06:11.271185 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/bin/bundle:22:in `load'
E, [2017-04-10T11:06:11.271198 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/bin/bundle:22:in `<main>'
E, [2017-04-10T11:06:11.271211 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
E, [2017-04-10T11:06:11.271224 #1249] ERROR -- : /usr/local/rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'

为什么我被告知“错过secret_key_base'生产'环境”即使我已经在我的config / secrets.yml文件中明确定义了它?它需要去别的地方吗?

0 个答案:

没有答案