I want to pass the RAILS_ENV
env variable to nginx and use it to set the value for the rails_env
directive.
I can read the value of the variable from the environment with LUA module:
location @app {
set_by_lua $env_rails_env 'return os.getenv("RAILS_ENV")';
return 200 'rails env is: ${env_rails_env}';
}
When I curl
it, I get the correct answer:
[jsosic@workstation ~]$ curl http://localhost:3005/
rails env is: development
But, if I want to use it as a value for nginx directive:
location @app {
set_by_lua $env_rails_env 'return os.getenv("RAILS_ENV")';
rails_env $env_rails_env;
limit_req zone=one burst=100;
passenger_enabled on;
}
I get the following log:
Message from application: '${env_rails_env}' database is not configured.
Available: ["default", "development", "test", "production"]
Is this even possible?
After some investigation it seems that
passenger_app_env
(whichrails_env
is aliased to) is not accepting the variable and instead treating it as a literal.https://github.com/phusion/passenger-docker/issues/28
So, instead of
$env_rails_env
expanding to the content of the$RAILS_ENV
read by lua, it's treated as a string$env_rails_env
. That's why the log line is reportingdatabase not configured
.Also, per nginx Q & A, variables shouldn't be used in configuration files:
What I ended up is using
envsubst(1)
.