独角兽不读取 ENV 变量

Unicorn not reading ENV variables

我在使用 Unicorn 和 nginx 的生产 Ubuntu 服务器上设置 SECRET_KEY_BASE 时遇到了一些问题。我将变量添加到 .bashrc 并且当我尝试 echo $SECRET_KEY_BASE 时它的读数很好,但由于某种原因我收到以下错误:

app error: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml` (RuntimeError)

此外,当我尝试在生产环境的控制台中使用 ENV["SECRET_KEY_BASE"] 访问变量时,我可以很好地读取它。

我尝试重启 Unicorn 和服务器,但没有用。知道为什么会这样吗?

您可能需要将变量添加到 unicorn.conf 文件中,因为看起来您正在与不同的用户启动 Unicorn 或没有采购您的 .bashrc

无论如何,我建议你使用dotenv gem to store your env variables in a .env file within your project. That is the cleanest way I know. If you need to have capistrano integration and handle all the different environments with ease, you can also use dotenv-deployment gem。