Phusion passenger does not see environment variables?

We run ubuntu servers with Nginx + Phusion Passenger for our applications with 3.0x rails.

I have an environment variable set in / etc / environment on test machines:

MC_TEST=true 

If I run the console (bundle exec rails c) and print ENV ["MC_TEST"], I see 'true'. But, if I put the same code on the page (<% = ENV ["MC_TEST"]%>), it does not see anything. This variable does not exist.

Which begs my question:

1 - How can I get environment variables in a passenger with nginx (and not apache SetEnv)?

2 - Why does the Passenger not have the proper environment?

+6
source share
3 answers

Passenger fusion v4 + allows you to read environment variables directly from a bashrc file. Make sure that bashrc lives in the home folder of the user under which the passenger process is running (in my case it was ubuntu, for ec2 linux and nginx)

Here is the documentation that details bashrc

+7
source

I have the same problem with you when using a passenger with nginx and nginx init script on ubuntu. The reason is because I use sudo service nginx restart (installed init script) to run nginx and
it was run as root, and root did not receive a user environment variable. There are two solutions for this. One of them starts nginx manually.

 sudo service nginx stop sudo -E /path/to/your/nginx 

one adds env to your nginx init script

 export MC_TEST=true 

The latter solution is somehow ugly, but it works. And I think the best way to find the configuration is to tell the init script to save the user interface.

+4
source

I got another ugly solution.

 env_file = '/etc/environment' if File.exist?(env_file) text = File.open(env_file).read text.each_line do |line| key, val = line.split('=', 2) ENV[key] = val.strip end end 
0
source

Source: https://habr.com/ru/post/915459/


All Articles