1

This is my VirtualHost file

NameVirtualHost *:80
<VirtualHost *:80>

DocumentRoot /var/www/html/backendtwo/
ServerName www.designer-school.com

</VirtualHost>

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

</VirtualHost>

joshhornby.co.uk is the root directory and the reason I am adding this is because after adding the first VirtualHost for designer-school.com any url on joshhornby such as joshhornby.co.uk/typewriter stops working. I can't access my blog posts either, try it out for your self joshhornby.co.uk is the address. The blog address are permalinked like this http://joshhornby.co.uk/post/web-course

As you can see this returns a 404.

My question is how can I serve two websites on the same server which doesn't stop one website from working as it should.

2 Answers2

2

You should use NameVirtualHosts.

Put a

NameVirtualHost *:80

before your vhost configurations.

etagenklo
  • 5,834
  • 1
  • 27
  • 32
2

Try NameVirtualHost * instead of *:80

The reason for the behavior you described, requesting joshhornby.co.uk opens the first one, is that NameVirtualHost *:80 will match the first VirtualHost *:80 definition.

If you use just NameVirtualHost *, then you're telling apache to search all VirtualHost definitions to find the best match, instead of the first positive match.

Marcel
  • 1,730
  • 10
  • 15
  • There's no change in the search behavior between `*` and `*:80` - both will search for a matching `ServerName` or `ServerAlias`, and only fall back to the first defined if no match is found. – Shane Madden Apr 09 '13 at 06:37