Why is my Apache virtualhost showing the default page for Apache?

Solution 1:

You need to modify the root directory for your virtual host. Otherwise you will have a subdomain which will show exactly the same data as your main domain.

For subdomain.domain.com you should set the DocumentRoot of the subdomain to DocumentRoot /var/www/page1 and for subdomain2.domain.com to DocumentRoot /var/www/page2 etc.

Check out the examples

Solution 2:

Your configuration should look like this:

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName    domain.com
  ServerAlias   www.domain.com
  DocumentRoot  /var/www/ivan # absolute path to your web root
</VirtualHost>

<VirtualHost *:80>
  ServerName    subdomain1.domain.com
  ServerAlias   www.subdomain1.domain.com
  DocumentRoot  /var/www/sub1 # absolute path to your web root
</VirtualHost>

<VirtualHost *:80>
  ServerName    subdomain2.domain.com
  ServerAlias   www.subdomain2.domain.com
  DocumentRoot  /var/www/sub2 # absolute path to your web root
</VirtualHost>