Name based virtual hosts aren't working

Discussion in 'Apache' started by coder11, Jan 22, 2010.

  1. #1
    Hi!

    I want to do the following:

    Register a domain, add several CNAMES to my DNS and make Apache load files from different directories based on the url name.

    So I've created a file for virtual host configuration in directory "sites-available". Then I include it in apache2.conf:

    # Include the virtual host configurations:
    Include /etc/apache2/sites-enabled/
    Code (markup):
    Configuration file looks like the following (the complete content is attached):

    <VirtualHost *:80>
            ServerName coolbox.org.ru
            ServerAlias coolbox.org.ru *.coolbox.org.ru
            DocumentRoot /var/www
    </VirtualHost>
    ...
    <VirtualHost *:80>
        DocumentRoot /home/testuser/www
        ServerName  testuser.coolbox.org.ru
        ServerAlias testuser.coolbox.org.ru *.testuser.coolbox.org.ru
    </VirtualHost>
    Code (markup):
    My domain is not ready yet, so I try to test it by editing hosts file in my Windows system (my real IP instead of 123.123.123.123):

    123.123.123.123 www.coolbox.org.ru
    123.123.123.123 www.testuser.coolbox.org.ru
    123.123.123.123 www.HiDaN.coolbox.org.ru
    123.123.123.123 www.coder11.coolbox.org.ru
    Code (markup):
    My problem is only one of the urls works fine (Apache takes files from the right directory). Others "leed to" the first entry (DocumentRoot /var/www). Changing the order of hostnames in hosts file affects nothing. Changing the virtual hosts orders causes another url to work fine while others still "leed to" /var/www

    Any Ideas how to solve this?

    Regards.
     

    Attached Files:

    coder11, Jan 22, 2010 IP