Page 1 of 1

Problems with apache2 multiple virtual hosts

PostPosted: 10. January 2013 23:51
by novatec1@aol.com
I have an apache2 server that has been used to host one virtual site. I tried a add a second site (site2) but after creating the second virtual host it shows site1. Each site works independently as long as the other sites virtual host code is commented out. Any help is greatly appreciated. The code is as follows:

NameVirtualHost *:80

<VirtualHost site1.com:80>
ServerName site1.com
DocumentRoot /home/design/vhosts/site1.com/htdocs
ServerAlias http://www.site1.com
</VirtualHost>


<VirtualHost site2.com:80>
ServerName site2.com
DocumentRoot /home/design/vhosts/site2.com/htdocs
ServerAlias http://www.site2.com
</VirtualHost>

Re: Problems with apache2 multiple virtual hosts

PostPosted: 14. January 2013 23:05
by JonB
OK -

One thing before you go back to work on this - normally you would create an operational default fall-back vhost - in the case of lammp - often /opt/lampp/htdocs. I usually put the server IP+a description as the ServerName in the default vhost. Plus you would usually have some <Directory> entries for each of your vhosts, but you may be doing everything in .htaccess. But those are comments only

Now try this syntax:

Code: Select all
NameVirtualHost *

<VirtualHost *>
ServerName www.site1.com
DocumentRoot /home/design/vhosts/site1.com/htdocs
</VirtualHost>

<VirtualHost *>
ServerName www.site2.com
DocumentRoot /home/design/vhosts/site2.com/htdocs
</VirtualHost>



Good Luck
8)