# Is nginx.conf file dynamically updatable

**URL:** <https://www.ruby-forum.com/t/is-nginx-conf-file-dynamically-updatable/187930>\
**Category:** NGINX\
**Created:** [May 2, 2010, 1:22pm UTC](https://www.ruby-forum.com/t/is-nginx-conf-file-dynamically-updatable/187930 "2010-05-02T13:22:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![myschizobuddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@myschizobuddy](https://www.ruby-forum.com/u/myschizobuddy)\
**Post date:** [May 2, 2010, 1:22pm UTC](https://www.ruby-forum.com/t/is-nginx-conf-file-dynamically-updatable/187930/1 "2010-05-02T13:22:06Z")

</div>

Inorder to make a simple UI for editing nginx.conf. I need a way to edit  
nginx.conf without having to open it up in a text editor. Does nginx  
have an  
api that i can use to edit information that is inside nginx.conf. This  
will  
help newbies add virtual host information and edit parameters via a UI.

---

<div class="post-metadata">

**Author:** ![myschizobuddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@myschizobuddy](https://www.ruby-forum.com/u/myschizobuddy)\
**Post date:** [May 2, 2010, 11:15pm UTC](https://www.ruby-forum.com/t/is-nginx-conf-file-dynamically-updatable/187930/2 "2010-05-02T23:15:35Z")

</div>

There’s no API that I know of, unless you want to make your own module.  
You  
could try having a separate directory for virtual hosts included and use  
a  
database to store and generate the configuration. It’d be a lot easier  
than  
trying to interpret the configuration as well.

---

<div class="post-metadata">

**Author:** ![myschizobuddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@myschizobuddy](https://www.ruby-forum.com/u/myschizobuddy)\
**Post date:** [May 3, 2010, 3:08pm UTC](https://www.ruby-forum.com/t/is-nginx-conf-file-dynamically-updatable/187930/3 "2010-05-03T15:08:25Z")

</div>

So I store the configuration in a database or xml file or whatever, and  
then  
generate the conf file from it.  
thank you.

---

<div class="post-metadata">

**Author:** ![myschizobuddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@myschizobuddy](https://www.ruby-forum.com/u/myschizobuddy)\
**Post date:** [May 3, 2010, 3:25pm UTC](https://www.ruby-forum.com/t/is-nginx-conf-file-dynamically-updatable/187930/4 "2010-05-03T15:25:58Z")

</div>

On Mon, May 3, 2010 at 3:07 PM, Ziyad S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> So I store the configuration in a database or xml file or whatever, and  
> then generate the conf file from it.  
> thank you.

Also, using a templating system with a scripting language (say, erb +  
ruby  
or whatever you’re comfortable with) or the good old m4 may be viable,  
and  
probably simpler to use and implement. This is very easy and very  
convenient  
if you have to generate lots of different configurations (say, for n  
virtual  
hosts, or n virtual hosts on n servers) but which all share a limited  
number  
of prototype configurations.

Bye

---

<div class="post-metadata">

**Author:** ![myschizobuddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@myschizobuddy](https://www.ruby-forum.com/u/myschizobuddy)\
**Post date:** [May 3, 2010, 6:37pm UTC](https://www.ruby-forum.com/t/is-nginx-conf-file-dynamically-updatable/187930/5 "2010-05-03T18:37:57Z")

</div>

I have a php command line script that builds separate conf files in  
one of my servers and does simple string replacement.

Also remember you can use includes so you can leave the main  
nginx.conf alone and have it include stuff from another directory you  
write out…

---

<div class="post-metadata">

**Author:** ![myschizobuddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@myschizobuddy](https://www.ruby-forum.com/u/myschizobuddy)\
**Post date:** [May 4, 2010, 12:48pm UTC](https://www.ruby-forum.com/t/is-nginx-conf-file-dynamically-updatable/187930/6 "2010-05-04T12:48:56Z")

</div>

nginx.conf file in inf format or any other template based format would  
have  
been the easiest thing to do. perhaps future version of nginx can go  
down  
this route.

---

<div class="post-metadata">

**Author:** ![myschizobuddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@myschizobuddy](https://www.ruby-forum.com/u/myschizobuddy)\
**Post date:** [May 4, 2010, 1:05pm UTC](https://www.ruby-forum.com/t/is-nginx-conf-file-dynamically-updatable/187930/7 "2010-05-04T13:05:55Z")

</div>

On Tue, May 4, 2010 at 12:48 PM, Ziyad S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> nginx.conf file in inf format or any other template based format would have been theÂ easiestÂ thing to do. perhaps future version of nginx can go down this route.

I advocate the templating way.. but I hope it doesn’t get into nginx  
properly. Managing the generation of it’s own configuration files is  
generally a bad idea… then why not make coffee as well? 😉

---

<div class="post-metadata">

**Author:** ![myschizobuddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@myschizobuddy](https://www.ruby-forum.com/u/myschizobuddy)\
**Post date:** [May 7, 2010, 10:10am UTC](https://www.ruby-forum.com/t/is-nginx-conf-file-dynamically-updatable/187930/8 "2010-05-07T10:10:18Z")

</div>

agree that hierarchy in inf will be ugly.  
you have to be a guru in regular expressions to create a UI for the  
current  
nginx configuration format. with xml, json yaml etc their are plenty of  
libraries that can read and right them easily.  
Or Nginx can provide an api that i can use to read and write nginx.conf  
files. that’s for Igor to decide.

---

<div class="post-metadata">

**Author:** ![myschizobuddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@myschizobuddy](https://www.ruby-forum.com/u/myschizobuddy)\
**Post date:** [May 7, 2010, 10:19am UTC](https://www.ruby-forum.com/t/is-nginx-conf-file-dynamically-updatable/187930/9 "2010-05-07T10:19:40Z")

</div>

json is great for interchange but i don’t think it’s a decent readable  
syntax.

xml really is king there, still, imho.

anyway - you could take the C code that parses the nginx configuration  
and make a PHP module or something out of it 😉

---

<div class="post-metadata">

**Author:** ![myschizobuddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@myschizobuddy](https://www.ruby-forum.com/u/myschizobuddy)\
**Post date:** [May 7, 2010, 12:21pm UTC](https://www.ruby-forum.com/t/is-nginx-conf-file-dynamically-updatable/187930/10 "2010-05-07T12:21:26Z")

</div>

Why would you want a UI anyway? Unfortunately, to be a web developer,  
you will have to have some kind of understanding of a few things like a  
server-side language, SQL, webserver configs, javascript, maybe CSS,  
etc. A UI is avoiding the problem. If you find the nginx configs to  
complicated (and I definitely don’t), then maybe the answer is a  
suggestion to change the configs for readability, not scriptability.

---

<div class="post-metadata">

**Author:** ![myschizobuddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@myschizobuddy](https://www.ruby-forum.com/u/myschizobuddy)\
**Post date:** [May 4, 2010, 5:58pm UTC](https://www.ruby-forum.com/t/is-nginx-conf-file-dynamically-updatable/187930/11 "2010-05-04T17:58:38Z")

</div>

the syntax right now is great. very structured and simple. (my only  
complaint is how location blocks work, partly is syntax and partly is  
just how it works) otherwise i think it is great.

anything can be scripted and anything can have a UI thrown onto it.

i don’t see how inf or xml or anything would make it any easier to  
have to make a UI for different location blocks, rewrite rules, other  
complex, and other freeform, non-cookie-cutter kind of configuration  
items.

besides, infs are one-dimensional, creating a hierarchy on that would  
be ugly and hard to read.
