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

I am trying to configure apache2 to have the following virtualhosts:

  • One that serves requests for www.mydomain.com
  • Another one that servers requests for anything else

How do I go about doing this?

share|improve this question

1 Answer 1

up vote 2 down vote accepted
  1. Have a NameVirtualHost *:80 directive, and define both VirtualHost blocks as <VirtualHost *:80>
  2. Put your "anything else" vhost first in the config (or alphabetically first in an included directory) with any ol' ServerName - it'll get all requests that don't match the other host - and your vhost with ServerName www.mydomain.com second.

That's all!

share|improve this answer
    
I've done what you said, but the anything else vhost is getting requests for www.mydomain.com. –  DanielGibbs Nov 18 '11 at 3:36
    
Are you sure the vhosts match the NameVirtualHost exactly? Please post your config. –  Shane Madden Nov 18 '11 at 3:37
    
pastebin.com/iG6Sr6fy. I'm trying to redirect anything that is not for mydomain.com to mydomain.com. –  DanielGibbs Nov 18 '11 at 3:41
1  
Hrm - not 100% sure if this is required (I've never tried without one), but try adding ServerName something.something.something to your 000-default vhost. –  Shane Madden Nov 18 '11 at 3:54
    
Straight from the Apache documentation: If you are using name-based virtual hosts, the ServerName inside a <VirtualHost> section specifies what hostname must appear in the request's Host: header to match this virtual host. –  Garrett Nov 18 '11 at 5:09

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.