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.

A few days ago I changed something on my Apache and it behaved strange.

For the VirtualHost, I had 1 entry

<VirtualHost *:80>
  ServerName siteA.com
  ...
  <Directory "/path/to/siteA.com">
  </Directory>
</VirtualHost>

Then added a 2nd one:

<VirtualHost siteB.com:80>
  ServerName siteB.com
  ...
  <Directory "/path/to/siteB.com">
  </Directory>
</VirtualHost>

As you see, I replaced the *:80 with the actual name. The result was that if you typed siteA.com you end up seeing siteB.com content. The address bar would still say siteA.com all the time.. but it was siteB.com content.

(My previous question as to why this happened has been answered.. this is a NEW question)

I want to reproduce this behavior but for 3 sites in the following manner:

siteA.com shows siteA.com <--- normal
siteB.com shows siteC.com <--- not normal
siteC.com shows siteC.com <--- normal

All my attempts of doing this end up making all sites point to the named domain.

How can I do this?

Thank you.

Blockquote

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Your VirtualHost directives need to match your NameVirtualHost directive. If you have

NameVirtualHost *:80

Then they must all use

<VirtualHost *:80>

If you're mixing up name based and IP based virtual hosts, then you should use the actual IP addresses everywhere, not *. See the note here.

share|improve this answer

Using your example and what DerfK said, you could add DocumentRoot directives to each <VirtualHost *:80> section and then just make the DocumentRoot for the "SiteB.com" site point to /path/to/siteC.com:

<VirtualHost *:80>
  ServerName siteA.com
  DocumentRoot /path/to/siteA.com
  ...
  <Directory "/path/to/siteA.com">
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerName siteB.com
  DocumentRoot /path/to/siteC.com
  ...
  <Directory "/path/to/siteC.com">
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerName siteC.com
  DocumentRoot /path/to/siteC.com
  ...
  <Directory "/path/to/siteC.com">
  </Directory>
</VirtualHost>
share|improve this answer

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.