title: nginx on localhost - wildcard domains and wildcard subdomains
body: <p>I configured nginx (and dnsmasq) to listen to <code>example.test</code> and <code>*.example.test</code> wildcard subdomain. Everything seems to work fine. Here is nginx.conf:</p>
  
  <pre><code>server {
      listen 80;
      server_name  ~(\.)?example\.test$;
  ...
  }
  </code></pre>
  
  <p>Now I want to respond to all other <code>*.test</code> domains from their own directory on disk. I just don't know how to make it happen, following config doesn't work (just disables above configuration):</p>
  
  <pre><code>server {
      listen 80;
      server_name \.test;
  ...
  }
  </code></pre>
  
  <p>Even following configuration has same effect:</p>
  
  <pre><code>server {
      listen 80;
      server_name ~(?!(\.)?example)\.test;
  ...
  }
  </code></pre>
  
  <p>Both these configs work, but disables *.example.test and example.test configuration and responds to them just as other <code>*.test</code> domains.</p>
  
  <hr>
  
  <p>Here is my question:</p>
  
  <p>How can I configure nginx to respond to <code>*.test</code> but respond to <code>example.test</code> and <code>*.example.test</code> in a different way?</p>