Zephni
Zephni

Reputation: 873

Apache virtual hosts - server ip directing to virtual host instead of /var/www/html

I have set up a linux box mainly for testing and I have got to a stage were apache, mysql and php are running. I followed tutorials on how to set up virtual hosts so I can point domains to it but something strange is happening. This is my httpd-vhosts.conf file that I have included in my httpd.conf file:

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName thedomain.co.uk
  DocumentRoot /var/www/thedomain
</VirtualHost>

When I go to thedomain.co.uk it is pointing to the correct place as you'd expect. But when I go to my servers ip, internal or external it is going to the same directory as the virtual host. Could you guys think of any reason that is? I would expect it to go to /var/www/html by default? Oh and I'm running CentOS 6.3

Thanks in advance for any answers!

Upvotes: 0

Views: 766

Answers (1)

NimChimpsky
NimChimpsky

Reputation: 47290

You have used wildcard to point everything at DocumentRoot /var/www/thedomain

You need to create second listing :

<VirtualHost myotherdomain.co.uk:80>
  ServerName myotherdomain.co.uk
  DocumentRoot /var/www/myotherdomain
</VirtualHost>

where your other domain is whatver ip and the document root, points to your choise.

The first vhost listing is also used as the default ... so if you were to use localhost it would resolve to whatever is first in list.

Upvotes: 1

Related Questions