I have a Windows Domain Controller and we use it for DNS for our internal network. I have an Ubuntu box with an IP address of Within the Windows DNS I created the forward and reverse lookup entries for the name Endymion.

Naturally when ever I FTP/SSH/HTTP/etc to the hostname Endymion it resolves correctly to my Ubuntu box.

I wanted to do some web development on this box for an existing site. There were problems when I placed the website in a subfolder of /var/www/. Let's just say it was in folder /var/www/projectx/. The issue involved the incorrect resolution of non-relative urls.

So I figure I could create a new DNS entry for the hostname projectx. Sure enough when I FTP/SSH/HTTP/etc to the hostname projectx it takes me to the same ubuntu box as the hostname Endymion...this is what I would expect. I now have two hostnames for the same box.

I then create a Virtualhost entry in httpd.conf that looks like the following:

<VirtualHost *:80>
        DocumentRoot /var/www/projectx
        ServerName projectx
        ServerAlias projectx

Sure enough when I go to a browser and type in http://projectx/ it takes me to the correct subfolder. Everything works!!!

Not so fast.

I then go to http://endymion/ and instead of taking me to /var/www/ it takes me to /var/www/projectx/

Clearly I'm missing something. Help please! ;)

  • 1
    Do you have any _default_ virtual hosts defined anywhere? – Eli Sand Apr 4 '12 at 0:47
  • What's the output from apache2ctl -S? – Shane Madden Apr 4 '12 at 0:48

Take a look through the Apache documentation on name-based virtual hosts, and you'll find this bit of information:

Main host goes away

If you are adding virtual hosts to an existing web server, you must also create a block for the existing host. The ServerName and DocumentRoot included in this virtual host should be the same as the global ServerName and DocumentRoot. List this virtual host first in the configuration file so that it will act as the default host.

In other words, as soon as you create one virtual host, the DocumentRoot in your main server configuraiton becomes irrelevant. Apache will select the first defined virtual host for names that do not explicitly match a ServerName or ServerAlias directive, so you will need to create an entry for your main host in the configuration file before any other VirtualHost blocks.


I think you will need to create a virtualhost entry for endymion as well, something like:

<VirtualHost *:80>
        DocumentRoot /var/www/example
        ServerName endmymion
        ServerAlias endmymion

Of course using default vhost also works as commented above.

  • You shouldn't have to create a virtual host entry for every single possible domain that points to your server just to prevent access. His problem is that Apache, by default, has an allow all access rule. What very few people know to do is set a deny all rule for "/" so that the server by default is locked down unless you explicitly specify access. – Eli Sand Apr 4 '12 at 0:49
  • I don't think preventing access was the problem in this case. I agree though with doing default deny access and opening access on a case by case basis. That should be part of any security conscious design strategy. – aseq Apr 4 '12 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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