Phusion Passenger 4 and nginx cannot see environment variables in Ubuntu Linux

According to the documentation at https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#env_vars_passenger_apps 15.3.5 Phusion Passenger should read environment variables from .bashrc. I am trying to run rails 4.2 application from a user account named rails using nginx and Phusion, and get a 502 bad gateway error when I try to load it in a browser. This process works under the correct user. When I open the ruby ​​console in the rails application directory, I see environment variables from my bashrc, including secret_key_base. However, when I finish my nginx log, I get a message stating that it cannot find secret_key_base. I tried adding this elsewhere, including / etc / bash.bashrc and / etc / nginx.conf.

+4
source share
1 answer

I found the answer to this terrible question. Reply to https://github.com/phusion/passenger/wiki/Debugging-application-startup-problems under the heading "Early Termination in Bash". It turns out Ubuntu.bashrc does not start if the shell is not interactive. Phusion Passenger does not start in an interactive shell. Therefore, we do not load these environment variables for the Phusion Passenger process.

Mike's comment was on the go. If you are using rvm then nginx points to a ruby ​​script that you can put environment variables before running ruby.

passenger_ruby /home/rails/.rvm/gems/ruby-2.2.1@was_i_towed/wrappers/ruby;

nginx.conf. vi nano, EXPORT SECRET = .

, /etc/environment .

Phusion Passenger 5, nginx.conf.

+6

All Articles