简体   繁体   中英

passenger/nginx - environment variable passing, or passenger variable passing

We have 2 rails environments with the same code. 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.

in the admin users .profile file I have:

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.

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!

So - can anyone tell me how to properly do this? Under no circumstances do we want this variable in ruby/rails/app code.

If you are using nginx with passenger (ie passenger included in nginx installation), the configuration is as follows:

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

Try passenger_set_cgi_param MC_TEST true in your nginx configuration

passenger_set_cgi_param docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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