Want to access UNIX environment variable

E. Westbrook nginx at westbrook.com
Thu Mar 7 09:17:04 UTC 2013

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.


On 02/27/2013 11:22 PM, amodpandey wrote:
> 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
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

More information about the nginx mailing list