I've configured two Virtual Hosts using a single IP and following the documentation. Here the conf:

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server host1.example.com (/etc/httpd/conf/httpd.conf:1019)
         port 80 namevhost host1.example.com (/etc/httpd/conf/httpd.conf:1019)
         port 80 namevhost host2.example.com (/etc/httpd/conf/httpd.conf:1024)

If I point my browser to host1.example.com or host2.example.com, I can see the correct corresponding page. If I point to the server name server.example.com, I see the host1.example.com index.html, and not the index.html in the corresponding DocumentRoot (/var/www/html). Is this the correct behaviour?

  • show us your actual apache configuration, I'm not sure what you have given us. – X Tian Feb 9 '14 at 15:28
  • That was the output of httpd -S. – ludiegu Feb 11 '14 at 14:40

Yes, the behavior changes when you enable virtual hosts from serving the global DocumentRoot directory to serve the first defined virtual host.

You should set a first virtual host (that appears in your configuration) to serve /var/www/html and then one for host1 and another for host2.

  • Makes sense. And what if I would not use the DocumentRoot /var/www/html directory? Should I comment it in the httpd.conf? – ludiegu Feb 11 '14 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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