【发布时间】:2014-08-18 00:54:19
【问题描述】:
所以我试图让我的第一个 ruby on rails 应用程序运行,并且在第一次运行“rails s”后,当我导航到 localhost:3000 时收到以下消息:
内部服务器错误
您必须在应用的配置中设置 config.secret_key_base。
我做了一些研究,看起来我需要配置我的 secrets.yml 文件,但不确定它应该是什么样子。这是我的 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: fe3ffe8d0308f92a4765f3ea02264cd24f1ddc9dd5a64aa601c61402c85e2de4d5fb74df8d66ef6d2a43dee34584dce87a51f83050d4d1d57320b5e846a6a8aa
test:
secret_key_base: fe3ffe8d0308f92a4765f3ea02264cd24f1ddc9dd5a64aa601c61402c85e2de4d5fb74df8d66ef6d2a43dee34584dce87a51f83050d4d1d57320b5e846a6a8aa
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
开发和测试 secret_key_base 来自我运行“rake secret”时生成的密钥。
我应该在生产中放入什么 secret_key_base (这就是我推测的错误)?
编辑:我的 config/initializers/secret_token.rb 文件应该是什么样子?这就是我所拥有的:
Demoapp::Application.config.secret_key_base = fe3ffe8d0308f92a4765f3ea02264cd24f1ddc9dd5a64aa601c61402c85e2de4d5fb74df8d66ef6d2a43dee34584dce87a51f83050d4d1d67320b5e8
解决方案:我忘记将生成的密钥放在我的 config/initializers/secret_token.rb 文件中的引号中。 config/initializers/secret_token.rb 现在看起来像这样并且工作正常:
Demoapp::Application.config.secret_key_base = 'fe3ffe8d0308f92a4765f3ea02264cd24f1ddc9dd5a64aa601c61402c85e2de4d5fb74df8d66ef6d2a43dee34584dce87a51f83050d4d461d57320b5e>aa8
【问题讨论】:
-
应该删除 config/initializers/secret_token.rb 文件,并将其中的密钥放入生产服务器的 SECRET_KEY_BASE 环境变量中,如 @vee 所述。 Rails 4.1 中这一变化的重点是将所有“秘密”数据集中到一个单一文件 (secrets.yml) 中,并从代码库中获取 prod 秘密。
标签: ruby-on-rails ruby configuration-files