# Config file templating

**URL:** <https://www.ruby-forum.com/t/config-file-templating/228535>\
**Category:** NGINX\
**Created:** [April 26, 2013, 11:50am UTC](https://www.ruby-forum.com/t/config-file-templating/228535 "2013-04-26T11:50:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SSRenSS\_NeumannSS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@SSRenSS\_NeumannSS\_S](https://www.ruby-forum.com/u/SSRenSS_NeumannSS_S)\
**Post date:** [April 26, 2013, 11:50am UTC](https://www.ruby-forum.com/t/config-file-templating/228535/1 "2013-04-26T11:50:52Z")

</div>

Hi,

I’m in the mid of converting from lighttpd to nginx. There I have one  
small config snippet for each ‘subsite’ (it’s personal only, so lots of  
different unrelated stuff). Unfortunately, quite often a snippet  
contains a location part that should go into the main server block and  
one server block. With nginx, this is not possible as-is.

Example – file “sites/foo”:  
----------------------8\<---------------------  
location /foo {

# do something

}

server {  
include “listen”;  
server\_name [foo.example.com](http://foo.example.com)  
return 301 [http://example.com/foo$request\_uri](http://example.com/foo$request_uri)  
}  
----------------------\>8---------------------

Does anyone have a working solution (probably some template approach)  
which would allow to include the snippets in two places and ignoring  
‘the wrong part’? So that it might look like:

nginx.conf:  
----------------------8\<---------------------

# …

server {  
include “listen”;  
server\_name [example.com](http://example.com);  
include “snippets/\*”;  
}

include “snippets/\*”;  
----------------------\>8---------------------

sites/foo:  
-----------------------8\<--------------------

# if server

location /foo {

# do something

}

# endif

# if main

server {  
include “listen”;  
server\_name [foo.example.com](http://foo.example.com)  
return 301 [http://example.com/foo$request\_uri](http://example.com/foo$request_uri)  
}

# endif

----------------------\>8---------------------

Thanks,  
Ren
