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 Answers 2

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.

1
  • 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. Apr 9, 2013 at 6:37
2

You should use NameVirtualHosts.

Put a

NameVirtualHost *:80

before your vhost configurations.

2
  • See edit to how my httpd.conf looks now. joshhornby.co.uk now loads up designer-school.com for some reason! Apr 7, 2013 at 17:52
  • Actually it should be NameVirtualHost *
    – Marcel
    Apr 7, 2013 at 21:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .