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