Heroku 配置密钥库错误 [英] Heroku Config Secret Key Base Error

查看:29
本文介绍了Heroku 配置密钥库错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚使用 Git 将我的第一个应用程序推送到 Heroku,并立即出现了 Interanl 服务器错误.

Just pushed my first app to Heroku using Git and straight away got an Interanl Server Error.

您必须在应用的配置中设置 config.secret_key_base.

这是因为在我的 .gitignore 文件中包含以下文件:

This is because on my .gitignore file the following file is included:

config/initializers/secret_token.rb

我在此处为我的 .gitignore 文件使用标准模板:https://github.com/github/gitignore/blob/master/Rails.gitignore

I am using a standard template for my .gitignore file found here: https://github.com/github/gitignore/blob/master/Rails.gitignore

我的问题:我是否应该直接通过 Heroku 设置此密钥以增加安全性,如果是,如何设置?

My Question: Should I set this key via Heroku directly for added security and if so how?

我应该从我的 .gitignore 文件中删除这一行吗?

should I just remove this line from my .gitignore file?

推荐答案

除了将秘密令牌设置为 Heroku 上的 ENV 变量外,如 Nick Ginanto 所述,您还需要以下内容来完成这项工作.

In addition to setting the secret token as an ENV variable on Heroku, as outlined by Nick Ginanto, you also need the following to make this work.

.gitignore

将此文件中的行更改为:

Change the line in this file to:

MyApp::Application.config.secret_token = ENV['SECRET_TOKEN']

这将获取您使用 Heroku 的配置变量设置的秘密令牌.

This will then pick up the secret token you have set with Heroku's config vars.

为了在您的本地环境中提取令牌,您需要添加它.这里有很多选择,但最接近 Heroku 的是使用 foreman gem 和 <项目根目录中的 code>.env 文件..env 需要有 secret_token

In order for the token to be picked up in your local environment you will need to add it. There are a number of options here but the one closest to Heroku is to use the foreman gem along with a .env file in your project root. The .env will need to have the secret_token

SECRET_TOKEN=NKUd7gisd7fueAISDfg....

您可以使用 rake secret 命令来生成令牌.确保您的 .env 文件已添加到 .gitignore.

You can use the rake secret command to generate tokens. Make sure your .env file is added to .gitignore.

完成所有这些后,您将拥有 Heroku 和本地的不同令牌,并且您的令牌将不在您的源代码管理中.

With all this in place you will have different tokens for Heroku and local and your token will not be in your source control.

这篇关于Heroku 配置密钥库错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆