Non existing subdomain showing index.html of first vhost

4 posts / 0 new
Last post
#1 Wed, 10/24/2018 - 09:38

Non existing subdomain showing index.html of first vhost

Hello together!

I installed Virtualmin a few days ago so I can host a few websites of some friends of mine. My virtual host list looks like this:

  • domain-a.tld ---------------------> Top-level server
    • a.domain-a.tld ---> Sub server
    • b.domain-a.tld ---> Sub server
    • c.domain-a.tld ---> Sub server
  • domain-b.tld ---------------------> Top-level server
  • domain-c.tld ---------------------> Top-level server

If I request a subdomain that does not exist (e.g. foo.domain-c.tld) then I see the contents of a.domain-a.tld. I would like to get the same response (or actually no response) for non existing subdomains as here: - how can I achieve that?

If I request a domain (or subdomain) with https (e.g. https://domain-a.tld) although I haven't setup SSL for this domain then I see the contents of the first domain that actually has a SSL Certificate (which is domain-b.tld in my case). Should I create Lets-Encrypt-Certs for every vhost or is there another way to prevent this behaviour from happening? Maybe a 301 Redirect to http if https isn't available for the requested vhost?



Wed, 10/24/2018 - 09:48


With the way Apache works, if the DNS for a domain or sub-domain resolves to it, but it hasn't been configured with a website for that particular domain, it will show the default domain for that IP address.

My suggestion would be to choose a domain you want as the default, or maybe setup a generic site for that default, which will be seen anytime Apache receives a request for a domain it doesn't yet host.

To set a domain as the default, go into Server Configuration -> Website Options, and there, you can set it to be the default for the IP address.


Wed, 10/24/2018 - 10:44

Thanks for your fast reply eric! I did what you've described and it's working so far. The only problem is that the server is responding with status code 200. How can I make this default host return an error page with 404 status code?

I also checked the DNS Settings of one of the domains and found a record with a wildcard hostname: *.domain-c.tld IN A I'm wondering what the preferred solution to my problem is: removing wildcard records or setting up a catchall vhost like you described it?

Wed, 10/24/2018 - 11:22

There isn't a way to show a 404 error in those cases... if the domain resolves to an IP address that points to your server, then your server is going to respond, possibly with the default website in Apache.

It sounds like disabling that wildcard option (Website matches all Sub-Domains) may be what you're after.


Topic locked