使用 .env 文件在生产中设置 SECRET_KEY_BASE [英] Set SECRET_KEY_BASE in production using a .env file
问题描述
我在生产中的根文件夹中有一个 .env
文件.这个文件定义了 SECRET_KEY_BASE
,它在 config/secrets.yml
中使用.问题是我无法在 config/secrets.yml
之前加载我的 .env
文件.我试过使用 dotenv
gem 没有成功.
I've a .env
file in my root folder in production. This file defines SECRET_KEY_BASE
which is used in config/secrets.yml
. The problem is that I can't manage to load my .env
file before my config/secrets.yml
. I've tried using the dotenv
gem without success.
知道如何在生产中做到这一点吗?
Any idea on how todo this in production?
我不想在生产服务器上为我的 webmaster
用户全局设置它.SECRET_KEY_BASE
值应该只能由应用程序访问.
I don't want to set it globally for my webmaster
user on the production server. The SECRET_KEY_BASE
value should only be accessable for by application.
我使用的是 Rails 4.1.
I'm using rails 4.1.
推荐答案
我也使用 dotenv
gem.它几乎在所有情况下都对我有用.
I too use dotenv
gem. It works for me in almost all case.
这是我对 dotenv
gem 的配置(是的,我将 dotenv
放在 Gemfile
中).我只是创建了一个 aaaaa.rb
初始化文件.
This is my configuration of dotenv
gem (yes, i put dotenv
in Gemfile
). I just create an aaaaa.rb
initializer file.
config/initializers/aaaaaa.rb
#obscure name because rails load initializers/* files based on alphabets
require 'dotenv'
Dotenv.load
而且,在它没有的情况下,我最终在 config/boot.rb
文件中执行此操作
And, cases which it doesn't, i do this this finally in config/boot.rb
file
ENV["SECRET_KEY_BASE"] = "foobar"
这篇关于使用 .env 文件在生产中设置 SECRET_KEY_BASE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!