I'm not sure how to solve my problem. It is that my Apache2 is configured to serve 3 different VirtualHosts. That depends on the Domains.

The config is:

NameVirtualHost example.eu:80
<VirtualHost example.eu:80>
        DocumentRoot /var/www2
        ServerName www.example.eu
        # Other directives here
</VirtualHost>

NameVirtualHost example.de:80
<VirtualHost example.de:80>
    DocumentRoot /var/www3/drupal
    ServerName www.example.de
</VirtualHost>

NameVirtualHost test.de:80
<VirtualHost test:80>
    DocumentRoot /var/www1/drupal
    ServerName test.de
</VirtualHost>

If I go to www.example*.de* I arrive at example*.eu* (the first configured VirtualHost). Same thing with test.de. It seems the www. is misinterpreted by that config. What do I have to do to make Apache2 handle this correctly, so that with and without "www." I get where I want - each time. All DNS entrys go to the same Apache2 server IP. The server is supposed to handle the requests accordingly. With and without the "www" prefix.

Best, ww

link|improve this question
feedback

1 Answer

You misunderstood what means the hostname in <VirtualHost> directive. It refers to an IP address where the virtualhost "listens" (Apache can resolve the names to IP address). So, I recommend you a following configuration:

NameVirtualHost *:80
<VirtualHost *:80>
        DocumentRoot /var/www2
        ServerName example.eu
        ServerAlias www.example.eu
        # Other directives here
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www3/drupal
    ServerName example.de
    ServerAlias www.example.de
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www1/drupal
    ServerName test.de
    ServerAlias www.test.de
</VirtualHost>

You must use NameVirtualHost domain.name:80 or NameVirtualHost 1.2.3.4:80 if your virtual host listens different IP address than the default.

link|improve this answer
default VirtualHost overlap on port 80, the first has precedence - that's what I get now. I don't think that is the solution. – www Oct 13 '11 at 17:21
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.