Digital Memo All begin with 0 & 1

26Aug/090

Working solution for Apache Sub-domains configuration

I was testing the configuration of multiple sub-domains in Apache. Lets say I have a domain name of www.neobie.net . I am going to configure the sub-domains for neobie.net which are not in the same servers. These are the environment at the moment:

  • www.neobie.net resides in server A (IP: 1.0.1.10) running IIS
  • sub1.neobie.net, sub2.neobie.net, etc are required resides in Server B running on Apache. (IP: 1.0.1.20). XAMPP 1.7.2

The following code works for me. Append the codes to the end of httpd.conf

NameVirtualHost 1.0.1.20:80
<VirtualHost 1.0.1.20:80>
ServerName sub1.neobie.net
DocumentRoot C:/xampp/htdocs/sub1/
</VirtualHost>
<VirtualHost 1.0.1.20:80>
ServerName sub2.neobie.net
DocumentRoot C:/xampp/htdocs/sub2/
</VirtualHost>

Previously I tried with *:80 instead of [server-ip]:80 stated on most of the websites (e.g. <VirtualHost *:80> ). It doesn't work for me. It failed to separate my sub-domains. By using *:80, both my sub1.neobie.net and sub2.neobie.net point to the same document root C:/xampp/htdocs/sub1/

Theoretically, I can't see any difference, as *:80 and 1.0.1.20:80 both are pointing to same IP address 1.0.1.20 which is Server B isn't? Why do they work differently?

Conclusion: I must specify the exact Server IP Address for my sub-domains to work correctly :|