schickling schickling - 1 year ago 300
Bash Question

nginx: use environment variables

I have the following scenario: I have an env variable

defined and want to use it in a nginx block. Referring to the nginx documentation I use the
directive in the
file like the following:

user www-data;
worker_processes 4;
pid /run/;

env SOME_IP;

Now I want to use the variable for a
. I tried it like the following:

location / {
proxy_pass http://$SOME_IP:8000;

But I end up with this error message:
nginx: [emerg] unknown "some_ip" variable

Answer Source

The correct usage would be $SOME_IP_from_env, but environment variables set from nginx.conf cannot be used in server, location or http blocks.

You can use environment variables if you use the openresty bundle, which includes Lua.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download