I try to configure vhosts with and without additional per-vhost config with nginx. I think of something like this:
server {
listen 81;
server_name ~^(www\.)?(?<sname>.+?)$;
root /var/www/$sname;
include /etc/nginx/sites/$sname;
access_log /var/log/nginx/$sname/access.log;
error_log /var/log/nginx/$sname/error.log;
}
Then i could just touch /etc/nginx/mysite.example.com
to add a new site with static html, while i can edit the file for the vhost to add for example a reverse proxy directive or some rewrite rules.
The problem is, nginx seems to include the config when starting. And it would be more clean to have something like
for $config in /etc/nginx/sites:
{
server_name $config
root /var/www/$config
include $config
[...]
}
which should run at the start and not on the first request to the vhost.
I still do not know, if a script include is possible, but i am using a script to generate the static config now using jinja2 as template system.