title: nginx: how to get a server for the case of no Host: header?
body: <p>I've got a special server {} block for the case of people who use an IP address in a host header (<code>server_name ~^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+;</code>) and that works fine. I'd like a different server block for one when no host header at all is provided. I've been testing with:</p>
  
  <pre><code>telnet localhost 80
  GET /foobar HTTP/1.0
  </code></pre>
  
  <p>And I see from my logging (which has <code>"$http_host"</code> in the log_format) this shows up as <code>"-"</code> (hyphen not underscore). But this server block:</p>
  
  <pre><code>server {
          listen 80;
          listen [::]:80;
  
          # hyphen not underscore
          server_name ~^-*$;
  
          root /var/www/no-host;
          default_type text/plain;
          index foo.ey
          location / {
                  try_files $uri /foo.ey;
          }
  }
  </code></pre>
  
  <p>Never gets used, the request instead goes to default which has <code>server_name _;</code> (underscore not hyphen).</p>
  
  <p>My use case is similar to a domain parking site, I want a lot of hostnames to be handled, and all legit ones should be looked up in a database, but I want to screen certain illegitimate ones early.</p>