I'm writing Ansible playbooks to provision an Ubuntu 18.04 server.

I want to provision the server for a Rails application using Passenger and Nginx. I used geerlingguy.passenger from Ansible Galaxy to configure Passenger and Nginx.

In addition, I used zzet.rbenv to install ruby 2.5.3.

The Ansible playbooks seem to have executed correctly, and when I log into the server via SSH, everything seems to be working (rbenv is on the path, RAILS_MASTER_KEY environment variable is defined).

Deployment of my application via Capistrano also appears to run successfully.

However, when I attempt to visit the landing page, I get a Passenger error: "Web application could not be started by the Phusion Passenger application server."

Looking in /var/log/nginx/error.log, I see:

Missing encryption key to decrypt file with. Ask your team for your master key and write it to /var/www/releases/20191230212823/config/master.key or put it in the ENV['RAILS_MASTER_KEY'].

I'm not sure why the above error is happening, because I've already configured a persistent environment variable using the weareinteractive.environment role.

Inspecting /etc/environment confirms that RAILS_MASTER_KEY is defined, and I can see if it I log in manually as my 'deploy' user. However, /etc/nginx/nginx.conf shows that the default user is www-data:

user www-data;

I think this should be fine, because the environment variables are configured in a way that is not associated with a user account. So, why does Rails fail to see this environment variable even though I see it when I log in via SSH?

I'm able to execute the following command on the server and see the contents of the encrypted credentials file:

RAILS_ENV=production EDITOR=vim bundle exec rails credentials:edit

So what is going wrong when Nginx/Passenger launch Rails?

Edit: It seems like Passenger/Nginx do not load environment variables from /etc/environment, which mostly explains my problem. I'm trying to figure out the appropriate way to configure environment variables for Passenger using Ansible now.


Root cause: environment variables from /etc/environment are not passed to Passenger. The standard method seems to be passenger_env_var in your nginx config as suggested by user joshaidan.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.