# Dynamic config options from ENV

**URL:** <https://www.ruby-forum.com/t/dynamic-config-options-from-env/230236>\
**Category:** NGINX\
**Created:** [June 5, 2014, 6:01pm UTC](https://www.ruby-forum.com/t/dynamic-config-options-from-env/230236 "2014-06-05T18:01:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason\_sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@jason\_sam](https://www.ruby-forum.com/u/jason_sam)\
**Post date:** [June 5, 2014, 6:01pm UTC](https://www.ruby-forum.com/t/dynamic-config-options-from-env/230236/1 "2014-06-05T18:01:17Z")

</div>

Hi everybody,

is it possible to set a nginx config variable from an ENV variable? I  
tried  
several thing, but none of them worked. The most promising was  
specifying  
“env MY\_VAR;” at the top of the nginx.conf and then using its value via  
“my\_option $ENV{“MY\_VAR”};”. But it didn’t work. I always got an error  
about the line not being terminated.

1. Is it possible to set a config option via ENV varaibles
2. If so, does it have any performance implications? (The ENV wont  
change  
during run time)

Thank you very much for your help.

Max

---

<div class="post-metadata">

**Author:** ![namxam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f19dbf/32.png) [@namxam](https://www.ruby-forum.com/u/namxam)\
**Post date:** [June 5, 2014, 6:21pm UTC](https://www.ruby-forum.com/t/dynamic-config-options-from-env/230236/2 "2014-06-05T18:21:55Z")

</div>

On 5 June 2014 17:00, Maximilian S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> during run time)  
> You can’t do this nicely with nginx. Your best option is to  
> pre-process the config file each time you reload/etc, interpolating  
> the envvars so that nginx itself sees static values.

---

<div class="post-metadata">

**Author:** ![namxam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f19dbf/32.png) [@namxam](https://www.ruby-forum.com/u/namxam)\
**Post date:** [June 5, 2014, 6:50pm UTC](https://www.ruby-forum.com/t/dynamic-config-options-from-env/230236/3 "2014-06-05T18:50:48Z")

</div>

Thank you Jonathan,

I was afraid that this is the only option… really sad ☹

I am currently experimenting with docker and dynamic setups which work  
for  
all environments… too bad that we need to use a custom script do handle  
the  
problem at hand. But thank you very much.

Max

On Thu, Jun 5, 2014 at 6:21 PM, Jonathan M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![namxam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f19dbf/32.png) [@namxam](https://www.ruby-forum.com/u/namxam)\
**Post date:** [June 5, 2014, 8:35pm UTC](https://www.ruby-forum.com/t/dynamic-config-options-from-env/230236/4 "2014-06-05T20:35:07Z")

</div>

> I am currently experimenting with docker and dynamic setups which work for  
> all environments… too bad that we need to use a custom script do handle  
> the problem at hand.

Well probably not that bad if you can use something allready made:

[https://index.docker.io/u/shepmaster/nginx-template-image/](https://index.docker.io/u/shepmaster/nginx-template-image/)

rr
