My question is how to pass the system environment variable to nginx.conf?
I define a system variable CLASSPATH in /etc/profile:
export CLASSPATH=$CLASSPATH:$HADOOP_HOME/bin/hadoop classpath --glob
And I define tow variables in nginx.conf:
env TEST_ENV=/usr/local/test;
env $CLASSPATH;
and print the variables by lua:
location /lua {
default_type text/html;
content_by_lua '
ngx.say(os.getenv("TEST_ENV"));
ngx.say(os.getenv("CLASSPATH"));
';
}
The results as below:
ngx.say(os.getenv("TEST_ENV")); ====> /usr/local/test
ngx.say(os.getenv("CLASSPATH")); ====> nil
Looks the env directive can't pass the system value to nginx.conf
Any suggestion?
This is how I do it using fastcgi and hopefully it'll be useful to you or anyone out there. My env variables are defined under /etc/environment. Note that after you define them you can use
source /etc/environmentto make them available to your session.Let's take for example one of your variables. This would go under /etc/environment
CLASSPATH=$HADOOP_HOME/bin/hadoop classpathOnce these have been defined in the system, for nginx I'd add the following within the location block:
fastcgi_param CLASSPATH $CLASSPATH; include fastcgi_params;