1

i have a root server where i have apache2 running with some virtualhost configs handling 2 of my domains with some subdomains.

i realized if i try to access some url which is configured in my virtualhosts, then i get one of my configured virtualhosts shown.

For example i have a webmail client set up on webmail.mydomain.com. Now if i type something like hello.mydomain.com, then it shows my webmail client. There is absolutely nothing pointing to my webmail client or anything related to hello.mydomain.com. Why is that happening?

2 Answers 2

2

For requests that come in with no Host: header, or one that doesn't match the ServerName or ServerAlias of any of the enabled VirtualHosts, apache will serve the request from the first vhost it loaded.

To work around this situation, create a "default" vhost that gets loaded before all the others. The configuration of that vhost would be something like:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        Redirect 404 /
        ErrorDocument 404 "Site not found."
</VirtualHost>

This will display a 404 error for any non-matching requests.

2
  • I still wonder if there is any non-workaround way to do it.. Feb 2, 2013 at 16:07
  • @KarmaFusebox - I've never seen one.
    – EEAA
    Feb 2, 2013 at 16:21
1

If no ServerName matches the given domain then simply the first vhost that was read when firing up apache is displayed. I'm not aware of any possibility to disable this behaviour. A hacky workaround is to make sure a dummy vhost is read before all other VirtualHost blocks.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .