I created 2 virtual hosts http:// web1.com:2107 pointing to “/var/www/web1” folder and second http:// web2.com:2107 pointing to “/var/www/web2”. all subdomains in web2 are working fine, But in case of web1.com:2107 i am able to see only home page. when i try to open any subdomain from web1 like http:// games.web1.com:2107 it points to web2’s home page ie /var/www/web2/ directory
Is there anything wrong in configuration ?
below is the code for hosts i am using
<VirtualHost *:80>
ServerName web2.com
ServerAdmin myeow@web2.com
ServerAlias http://www.web2.com
DocumentRoot /var/www/web2
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/web2>
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/www/web2/error80.log
CustomLog /var/www/web2/access80.log Combined
</VirtualHost>
<VirtualHost *:2107>
ServerName web2.com
ServerAdmin myeow@web2.com
ServerAlias http://www.web2.com
DocumentRoot /var/www/web2
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/web2>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/www/web2/error.log
CustomLog /var/www/web2/access80.log Combined
LogLevel warn
CustomLog /var/log/apache2/web2.com_access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
===================================================================
NameVirtualHost *:2107
<VirtualHost *:2107>
ServerName web1.com
ServerAlias http://web1.com
DocumentRoot /var/www/web1
<Directory /var/www/web1/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
ErrorLog /var/www/web1/error.log
CustomLog /var/www/web1/access.log Combined
</VirtualHost>
When you have several VirtualHosts one of them is the default VirtualHost.
It’s the first one in alphabetic order of the file containing the definition of the VirtualHost.
When you remove a VirtualHost. If you still have an entry in the Hosts file or a DNS record, when the query is performed on your Apache server, if it cannot find the right VirtualHost (ServerName or ServerAlias), then the default one is taken to process the answer.
When you add a new VirtualHost, if you make a mistake in the ServerName or ServerAlias you’ll also have the default VH.
Update
Now that the question is complete I can see you are not using ServerAlias in the right way. All your subdomains should be listed in ServerAlias directives, without the http://
So you should have:
You could maybe try a *.web1.com.
Else when you use a name which is not listed the default vhost is used (and here vhost web2.com is defined before so it’s the default one on this port)