Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have an Apache2 configuration with multiple VirtualHosts. My DNS is set to accept *.<domain>.<tld> on multiple domains. Everything is working correctly but if I go to something-random-here.example.com I seem to get an invalid VirtualHost being selected (I am guessing the first or last one it finds). Is there a way to tell Apache to use certain rules if none of the VirtualHost entries match the domain or subdomain? I'd preferably like to return a 404.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Apache uses the first virtualhost if no name matches. Just configure a new virtualhost as the first one with a random name, displaying whatever you like - or returning a 404 page.

share|improve this answer
    
Thanks but could you please elaborate? I can't get this to work. –  Ryall Sep 7 '11 at 12:34
    
How are your apache2 configuration files layed out? Or which operating system do you use? Apache reads the configuration in a certain order, and the first VirtualHost it sees is the default one. It receives all traffic from unknown host names. So if you have a single configuration file, the first VirtualHost is it. If you have multiple ones, like on most linuxes, it may be the one called 0default or so... –  Moritz Both Sep 7 '11 at 15:00
    
I put some default configurations in the ports.conf. It wasn't working because I tried to match *:80 when I was using <ip>:80 on my virtualhosts. Instead I had to create a separate default entry for each IP and it works now. –  Ryall Sep 8 '11 at 15:31

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.