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.

Within Apache I had a vhost set up with ServerName host1.example.com

Within /etc/hosts there is an entry for host1

127.0.1.1 host1.example.com host1

And in /etc/hostname

host1

This is the Debian/Ubuntu way of creating an FQDN.

Apache seems to have a problem when serving content for a virtual host that has the same FQDN as the server itself.

When running nginx with a vhost for host1.example.com it has no problem picking up the Host header and using the correct vhost.

But when using Apache it has problems, it always uses 000-default. Deleting 000-default makes it switch to the next vhost and deleting all but the vhost file for the domain that I want to work finally makes it work.

NameVirtualHost is set to *

There are no error messages in the logs, no overlapping virtualhosts and the vhost config is perfectly fine.

<VirtualHost *>
        ServerAdmin webmaster@localhost
        ServerName host1.example.com

        DirectoryIndex index.php index.htm index.html
        DocumentRoot /var/www/host1.example.com

        <Directory />
            Options FollowSymLinks Includes -Indexes
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>
</VirtualHost>

Anyone have any ideas?

Edit:

apache -t -D DUMP_VHOSTS output:

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:*                    is a NameVirtualHost
         default server the.server.fqdn (/etc/apache2/sites-enabled/000-default:1)
         port * namevhost the.server.fqdn (/etc/apache2/sites-enabled/000-default:1)
         port * namevhost host1.example.com (/etc/apache2/sites-enabled/host1.example.com:1)
Syntax OK
share|improve this question

2 Answers 2

Well, it seems there is no real answer to this, it may only be a Debian/Ubuntu thing based on how they resolve their own FQDN.

I found that simply commenting out the host and FQDN resolution in /etc/hosts solved the problem.

#127.0.1.1 host1.example.com host1

However this is not an actual solution, this is required otherwise you get errors while trying to run sudo and other programs because it fails to resolve a hostname.

The simplest solution for me was to add a single line to 000-default:

ServerName localhost

This is not a real solution either as such, but it does mean it won't match for other hosts and because it is the first host Apache finds it will resolve to this host if a match is not found.

share|improve this answer
    
I didn't have that line in /etc/hosts, but I did have the virtual host I was trying to create as my /etc/hostname. Adding a ServerName to 000-default worked, thanks –  Kyle Cronin Dec 1 '12 at 4:39

Whenever Apache brings up the wrong vhost, httpd -t -D DUMP_VHOSTS is usually pretty good at pointing out what the problem is.

share|improve this answer
    
Please see my edited post with DUMP_VHOSTS output. –  Kura Nov 24 '10 at 16:17

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.