title: How do I configure apache to return 404 on unconfigured subdomains?
body: <p>I am self-hosting a website on a Debian computer with apache, and in my DNS configuration I have set all subdomains of my domain (*.mydomain.com) to go to the IP of my Debian computer. How do I configure apache so that if someone goes to a subdomain that doesn't have a virtual host, I have a separate file for each subdomain, they get a 404 error instead of seeing the content on the root domain? I have tried editing the 000-default.conf file and put the following in it:</p>
  <pre><code>&lt;VirtualHost *:80&gt;
          ServerName null
          Redirect 404 /
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost *:443&gt;
          ServerName null
          Redirect 404 /
  &lt;/VirtualHost&gt;
  </code></pre>
  <p>But now when I got to mydomain.com I get the following error:</p>
  <pre><code>This site can’t provide a secure connection
  mydomain.com sent an invalid response.
  ERR_SSL_PROTOCOL_ERROR
  </code></pre>
  <p>Oddly if I go to one of the subdomains that I have configured for mydomain.com it works correctly and I see the page that should be on the subdomain.</p>