Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need the following configuration:

  • access the page at project/www/index.php at the URL site.dev/index.php
  • access the page at project/www/admin/index.php at the URLs site.dev/admin/index.php and admsite.dev/index.php

I have the file /etc/apache2/sites-available/site as the following:

<VirtualHost site.igoru.dev>
        ServerAdmin webmaster@localhost
        ServerName site.igoru.dev
        DocumentRoot /var/www/site/www
        ErrorLog /var/log/apache2/error.site.log
        CustomLog /var/log/apache2/access.site.log combined
</VirtualHost>

<VirtualHost admsite.igoru.dev>
        ServerAdmin webmaster@localhost
        ServerName admsite.igoru.dev
        DocumentRoot /var/www/site/www/admin
        ErrorLog /var/log/apache2/error.site.log
        CustomLog /var/log/apache2/access.site.log combined
</VirtualHost>

When I restart Apache, it says that the first virtualhost overlaps with the second, and the first had precedence. "Perhaps you need a NameVirtualHost directive". When I open the URLs, both point to the www/index.php file.

I've read a little the documentation about that directive, but it didn't help me.
I'm a little noob with apache configs, and would like some help with this problem.

TY in advance.

share|improve this question
add comment

1 Answer

Since your VirtualHost blocks point at hostnames, they're binding to every request that comes in to the address that those names resolve to. Presumably, those resolve to the same address, and so the first block gets the address and the second gets nothing.

You probably already have a NameVirtualHost directive somewhere; check ports.conf. If not, set one (NameVirtualHost *:80), then change your VirtualHost blocks to match the name that's being configured for host headers:

<VirtualHost *:80>
        ServerName site.igoru.dev
        ...
</VirtualHost>
<VirtualHost *:80>
        ServerName admsite.igoru.dev
        ...
</VirtualHost>
share|improve this answer
    
I changed the VirtualHost names for *:80, as my ports.conf has the NameVirtualHost as you said. But now, when I restart Apache, it throws those warnings: _default_ VirtualHost overlap on port 80, the first has precedence and NameVirtualHost *:80 has no VirtualHosts –  Igoru May 2 '11 at 1:49
    
What do your VirtualHost blocks look like now? –  Shane Madden May 2 '11 at 3:11
    
pastie.org/1855560 –  Igoru May 2 '11 at 4:48
    
Seems like your NameVirtualHost *:80 directive is not taking effect. –  Shane Madden May 2 '11 at 6:23
    
and how can I doscover anything about that, or fix it? This line is in my ports.conf as you said. Additionally, I'm using the pristine apache2, as it came from Ubuntu 10.10 package manager. –  Igoru May 3 '11 at 15:13
show 1 more 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.