Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

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.

share|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
    
Because you have a virtualhost with header like <VirtualHost _default_:80>. Try to disable it. –  Gabor Garami Jul 9 '13 at 22:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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