shell environment variables in "include"-directive not working

Markus Grobelin grobi at koppzu.de
Sat May 15 17:11:06 MSD 2010


Hmm. Maybe you're right. The following one will do the trick, if your 
environment variables are prefixed with "ENV_", e.g. ENV_foo=bar, in the 
.env file:

     . conf/instance.env
     env_vars="`env | grep 'ENV_'`"

     find nginx/conf/ -type f -iname '*.conf' | while read file
     do
         for var in $env_vars; do
             vkey="`echo $var | cut -f1 -d=`"
             vvalue="`echo $var | cut -f2 -d=`"
             sed -e "s/\$${vkey}/`echo $vvalue`/g" -i $file
          done
     done

... so i can have configfiles like:

server {
     listen $ENV_httpdip:$ENV_port;

     server_name media$ENV_domainsuffix;

     # doc root
     root $ENV_instance/htdocs/superoperty;

     access_log $ENV_instance/logs/static/media.access.log;
     error_log $ENV_instance/logs/static/media.error.log;
}

Cheers,
Markus Grobelin



More information about the nginx mailing list