nginx配置的时候报错:
Missing
secret_key_base
for 'production' environment, set this value inconfig/secrets.yml
rails 的安全机制需要一个秘钥,在rails 4.x版本中, 秘钥的设置在 RAILS_ROOT/config/secrets.yml, 这文件一般形如:
development:
secret_key_base: XXXXXXX
test:
secret_key_base: XXXXXXX
# Do not keep production secrets in the unencrypted secrets file.
# Instead, either read values from the environment.
# Or, use `bin/rails secrets:setup` to configure encrypted secrets
# and move the `production:` environment over there.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
在非生产环境下, 秘钥都是'明文', '硬编码', 写在secrets.yml 里面的。这种方式会由于源代码的泄露, 造成安全问题, 所以这种方式存在安全隐患。
所以rails要求在生产环境下, 通过操作系统的环境变量来设置秘钥, 这样相对比较稳妥。
rails产生秘钥的指令: RAILS_ENV=production bundle exec rake secret
参考链接:
https://stackoverflow.com/questions/23726110/missing-production-secret-key-base-in-rails