Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phusion Passenger 4 & 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 be reading environmental variables from .bashrc. I am trying to run a rails 4.2 application from a user account named rails using nginx and Phusion passenger and get a 502 bad gateway error when I try to load it in the browser. The process operates under the correct user. When I open a ruby console in the rails app directory I see the environment variables from my bashrc including secret_key_base. However when I tail my nginx log the error I get is that it is not able to find secret_key_base. I have tried adding this elsewhere including /etc/bash.bashrc and /etc/nginx.conf.

like image 257
Matthew Zagaja Avatar asked Mar 07 '15 07:03

Matthew Zagaja


People also ask

What is Phusion Passenger server?

Phusion Passenger® is an open source web application server. It handles HTTP requests, manages processes and resources, and enables administration, monitoring and problem diagnosis. Phusion Passenger - the smart app server. Passenger is very easy to use, makes deploying in production much easier and is scalable.

What is passenger nginx?

The Passenger Nginx module registers Passenger-specific configuration options inside Nginx. You, the administrator, configure Passenger by adding Passenger-specific configuration options to the Nginx configuration file. Restart or reload Nginx to apply any configuration changes.

What is passenger in linux?

Passenger® is an app server that runs and automanages your web apps with ease. Also improves security, reliability and scalability.

What is the passenger app?

Passenger is the companion app to ForeFlight Mobile that answers the question “Are we there yet?” Built on ForeFlight's high-performance map engine, Passenger automatically connects to your pilot's ForeFlight app and displays the current route so you can monitor your flight's progress.


1 Answers

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

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

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

Is a line in my nginx.conf file. If I open this wrapper in vi or nano then I can add the EXPORT SECRET= to the top of the file and it works.

Other literature suggests that setting the environment variables in /etc/environment should also work.

This issue should also be rendered moot when upgrading to Phusion Passenger 5 which has a facility for specifying environment variables in nginx.conf.

like image 76
Matthew Zagaja Avatar answered Sep 23 '22 06:09

Matthew Zagaja