简体   繁体   English

Phusion Passenger 4和nginx在Ubuntu Linux中看不到环境变量

[英]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. 根据https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#env_vars_passenger_apps 15.3.5中的文档,Phusion Passenger应该从.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. 我正在尝试使用nginx和Phusion passenger从名为rails的用户帐户运行rails 4.2应用程序,并在我尝试在浏览器中加载时出现502错误的网关错误。 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. 当我在rails app目录中打开ruby控制台时,我会看到来自我的bashrc的环境变量,包括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. 但是当我关闭我的nginx日志时,我得到的错误是它无法找到secret_key_base。 I have tried adding this elsewhere including /etc/bash.bashrc and /etc/nginx.conf. 我尝试在其他地方添加它,包括/etc/bash.bashrc和/etc/nginx.conf。

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". 答案在https://github.com/phusion/passenger/wiki/Debugging-application-startup-problems的标题下“Bash中的提前终止”。 It turns out that the Ubuntu .bashrc does not run if the shell is not interactive. 事实证明,如果shell不是交互式的,则Ubuntu .bashrc不会运行。 Phusion Passenger does not run in an interactive shell. Phusion Passenger不在交互式shell中运行。 Therefore we do not load these environment variables for the Phusion Passenger process. 因此,我们不会为Phusion Passenger流程加载这些环境变量。

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. 如果您正在使用rvm,那么nginx指向一个ruby脚本,您可以在ruby启动之前将环境变量放入其中。

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

Is a line in my nginx.conf file. 是我的nginx.conf文件中的一行。 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. 如果我用vi或nano打开这个包装器,那么我可以将EXPORT SECRET =添加到文件的顶部并且它可以工作。

Other literature suggests that setting the environment variables in /etc/environment should also work. 其他文献表明,在/ etc / environment中设置环境变量也应该有效。

This issue should also be rendered moot when upgrading to Phusion Passenger 5 which has a facility for specifying environment variables in nginx.conf. 升级到Phusion Passenger 5时也应该解决这个问题,Phusion Passenger 5具有在nginx.conf中指定环境变量的工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM