Reputation: 841
I have deployed my Rails 4.2.0 app into a Ubuntu 14.04 VPS using NGINX, Unicorn and Capistrano. Everything works fine except by the missing of my secret_key_base in production environment.
Here is my secrets.yml production block:
production:
secret_key_base: <%= ENV["APP1_SECRET_KEY_BASE"] %>
In my ~/.bashrc in the server I have:
export APP1_SECRET_KEY_BASE=token
It's all ok with the variable:
deployer@euler:~$ echo $APP1_SECRET_KEY_BASE
token
deployer@euler:~$ irb
2.2.0 :001 > ENV["APP1_SECRET_KEY_BASE"]
=> "token"
2.2.0 :002 > exit
But when I try to access my app I get the error in the log/unicorn.log:
ERROR -- : app error: Missing `secret_token` and `secret_key_base` for 'production' environment, set these values in `config/secrets.yml` (RuntimeError)
Seems to me that the Unicorn cannot access those values. So I have tried to use the NGINX Env functionality, but again no success, tried both ways in my nginx.conf:
env APP1_SECRET_KEY_BASE;
and
env APP1_SECRET_KEY_BASE=token;
But again, no success. The configuration passes the nginx start but the app doesn't work.
I even tried to use the dotenv gem, but no success also.
Any tip of what may be happening?
Upvotes: 2
Views: 755
Reputation: 83
In /etc/nginx/nginx.conf
add the variables you need using:
passenger_env_var VARIABLE_NAME "value";
Upvotes: 2
Reputation: 107728
You can use the dotenv-rails
gem to accomplish this. Have a file in your shared
directory on your server called .env
and copy it into the current
directory on deploy.
That file would have some content like this:
SECRET_KEY_BASE=6c073f07...
The other benefit of using dotenv-rails
is that if your application requires any other environment configuration you now will have a place for it.
Upvotes: 0