Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
I still wonder if there is any non-workaround way to do it.. –  Karma Fusebox Feb 2 '13 at 16:07
    
@KarmaFusebox - I've never seen one. –  EEAA Feb 2 '13 at 16:21
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.