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 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 172.16.34.149. 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
</VirtualHost>

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! ;)

share|improve this question
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

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer

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
</VirtualHost>

Of course using default vhost also works as commented above.

share|improve this answer
    
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

 
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.