Hi, I have system where I have defined OS environment variable $ENV=prod or dev. I want to access this variable inside my nginx configuration. Please help. I have tried -g "env ENV" in command line. But how do I access it? $ENV does not work? Posted at Nginx Forum: http://forum.nginx.org/read.php?2,236654,236654#msg-236654
on 2013-02-27 07:49
on 2013-02-27 11:51
On 27 February 2013 06:49, amodpandey <nginx-forum@nginx.us> wrote: > Hi, > > I have system where I have defined OS environment variable $ENV=prod or dev. > I want to access this variable inside my nginx configuration. Please help. > > I have tried -g "env ENV" in command line. But how do I access it? $ENV does > not work? No, this isn't supported - both specifically what you tried, and the more general "envvars in config" concept. You'll have to find another way to achieve what you want. Jonathan -- Jonathan Matthews // Oxford, London, UK http://www.jpluscplusm.com/contact.html
on 2013-02-28 07:05
Let me put what I want to achieve. Before that I want to know what is this 'env' global directive for? I want to maintain a single set of configuration files for dev and prod. The machines would have environment variable set ENV=dev or ENV=prod. Based on the values of the ENV varibale I wanted to pick my upstream conf, either upstream_dev.conf or upstream_prod.conf through 'include upstream_$ENV.conf'. Please suggest an approach. Posted at Nginx Forum: http://forum.nginx.org/read.php?2,236654,236704#msg-236704
on 2013-02-28 07:14
Have puppet generate the configuration based on that variable. -- Snet form my moblie phoen. Please excues tpyos.
on 2013-02-28 07:22
Thank you. I am looking for an simpler ( direct ) approach. For now I have put a sed script in my bounce nginx which does that. Posted at Nginx Forum: http://forum.nginx.org/read.php?2,236654,236706#msg-236706
on 2013-02-28 11:54
On 28 February 2013 06:04, amodpandey <nginx-forum@nginx.us> wrote: > Let me put what I want to achieve. > > Before that I want to know what is this 'env' global directive for? I don't know. The documentation suggests it's not going to solve the problem you want; but I've not used it. > I want to maintain a single set of configuration files for dev and prod. The > machines would have environment variable set ENV=dev or ENV=prod. Based on > the values of the ENV varibale I wanted to pick my upstream conf, either > upstream_dev.conf or upstream_prod.conf through 'include > upstream_$ENV.conf'. > > Please suggest an approach. Use something that helps you template your config files. Chef, puppet, Erb, Perl, bash - whatever works for you. [ However, I will suggest that rolling your own templating setup is a strong indicator of an inexperienced sysadmin; one who doesn't yet understand the value of consistency, the principle of least surprise, and why NIH is a Bad Thing. ] HTH, Jonathan -- Jonathan Matthews // Oxford, London, UK http://www.jpluscplusm.com/contact.html
on 2013-03-07 10:17
Posting a bit late to this thread, but thought I'd contribute. Having
found no better way myself, the way I "import" environment variables
into my nginx configurations is as follows.
At top config level:
env MYVAR;
At http level:
perl_set $myvar 'sub { return $ENV{"MYVAR"}; }';
Then, for example, at server level:
root $myvar;
Works a treat. Obviously there must be an overhead cost with this
approach, but either it's small, or I'm small, because I haven't noticed
it. (And even then, if I found it significant, I'd probably get to work
on a proper patch, since environment variables are rather central to my
general service configuration strategy.)
I'd love to know if anyone does it differently and/or better. If a
helper is how it must be done, I'd actually prefer to use Lua -- but
"perl_set" is documented for use at the http config level, whereas
"lua_set" (for whatever reason) is not.
$0.02,
Eric
on 2013-03-11 22:40
Late to contribute as well but wanted to mention that we reference a single include in the main config that gets linked to the actual file at the deployment time only. Posted at Nginx Forum: http://forum.nginx.org/read.php?2,236654,237242#msg-237242
on 2013-03-11 22:41
Left out the fact make file is used to create the link. Posted at Nginx Forum: http://forum.nginx.org/read.php?2,236654,237243#msg-237243
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.