简体   繁体   English

乘客/ nginx-环境变量通过,或乘客变量通过

[英]passenger/nginx - environment variable passing, or passenger variable passing

We have 2 rails environments with the same code. 我们有2个具有相同代码的Rails环境。 One is staging, the other production. 一种是演出,另一种是制作。 Both run using the same 'production' rails settings. 两者都使用相同的“生产”导轨设置运行。

But, we'd like to know what environment we are on. 但是,我们想知道我们所处的环境。 I thought I could set an environment variable on the servers and read that out inside of rails, but, while that works from the console it doesn't work when running behind passenger. 我以为我可以在服务器上设置一个环境变量,然后在rails内读取它,但是,虽然可以从控制台运行,但是在乘客后面跑时却不起作用。

in the admin users .profile file I have: 在admin用户.profile文件中,我有:

export MC_TEST=true

But the nginx's/passengers running don't seem to be inside that same environment, and that variable is not set. 但是运行的nginx / passenger似乎不在同一环境中,并且未设置该变量。

I thought I could then maybe put something in the nginx.conf to get passed back to the rails environment, but obviously I am not doing that right either! 我以为我可以在nginx.conf中放一些东西,以传递回Rails环境,但是显然我也没有这样做!

So - can anyone tell me how to properly do this? 所以-谁能告诉我如何正确执行此操作? Under no circumstances do we want this variable in ruby/rails/app code. 在任何情况下,我们都不希望在ruby / rails / app代码中使用此变量。

If you are using nginx with passenger (ie passenger included in nginx installation), the configuration is as follows: 如果您将nginx与乘客一起使用(即nginx安装中包含的乘客),则配置如下:

server {
    server_name www.foo.com;
    root /webapps/foo/public;
    passenger_enabled on;

    passenger_env_var DATABASE_USERNAME foo_db;
    passenger_env_var DATABASE_PASSWORD secret;
}

https://www.phusionpassenger.com/library/config/nginx/reference/#passenger_env_var https://www.phusionpassenger.com/library/config/nginx/reference/#passenger_env_var

Try passenger_set_cgi_param MC_TEST true in your nginx configuration 在您的passenger_set_cgi_param MC_TEST true配置中尝试passenger_set_cgi_param MC_TEST true

passenger_set_cgi_param docs passenger_set_cgi_param文档

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

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