This is my VirtualHost file

NameVirtualHost *:80
<VirtualHost *:80>

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


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


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.


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.

  • 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 9 '13 at 6:37

You should use NameVirtualHosts.

Put a

NameVirtualHost *:80

before your vhost configurations.

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.