passenger / nginx - 环境变量传递,或乘客变量传递

时间:2021-11-17 00:23:43

We have 2 rails environments with the same code. One is staging, the other production. Both run using the same 'production' rails settings.

我们有2个具有相同代码的rails环境。一个是升级,另一个是生产。两者都使用相同的“生产”导轨设置。

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 /乘客似乎并不在同一个环境中,并且没有设置该变量。

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代码中使用此变量。

2 个解决方案

#1


2  

Try passenger_set_cgi_param MC_TEST true in your nginx configuration

在nginx配置中尝试使用passenger_set_cgi_param MC_TEST为true

passenger_set_cgi_param docs

#2


1  

If you are using nginx with passenger (i.e 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

#1


2  

Try passenger_set_cgi_param MC_TEST true in your nginx configuration

在nginx配置中尝试使用passenger_set_cgi_param MC_TEST为true

passenger_set_cgi_param docs

#2


1  

If you are using nginx with passenger (i.e 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