I'd like to configure Nginx in such way that I need minimal amount of efforts to add new sites.
I see this in the following way: when creating new site I put it in subfolder under /var/www, add new location in nginx config file which just includes config template for required site type. It can look like this:
server
{
listen 80;
server_name localhost;
root /var/www;
location /site1
{
include drupal.conf;
}
location /site2
{
include wordpress.conf;
}
}
But, unfortunately, this doesn't work in my case. The issue is with nested locations. I have the following lines in one of included templates:
...
location /core/
{
deny all;
}
location /
{
try_files $uri $uri/ @rewrite;
}
....
Nginx gives me the following errors:
location "/core/" is outside location "/site1" in ...
location "/" is outside location "/site1" in ...
So I need to specify full path for each site (like /site1/core/), but then I will not be able to extract it as one reusable piece.
Previously, as alternative, I configured multiple server directives with different server_name (site1.locahost, site2.localhost ...) and edited /etc/hosts file. In this case I didn't need nested locations as long as everything was under the root of domain. But, as I said, I'm looking for a way to simplify the workflow as much as possible and editing /etc/hosts seems to me like extra action which I' like to avoid.
So the question is how to best handle this situations? How do you organize work on different sites locally?