1

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

2 Answers 2

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.

1
  • 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 Dec 1, 2012 at 4:39
0

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

1
  • Please see my edited post with DUMP_VHOSTS output.
    – Kura
    Nov 24, 2010 at 16:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .