Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I manage a few Mac OSX XServes for production websites and have recently run into an issue dealing with the server resolving the DNS of some of the sites. Further investigation revealed that httpd.conf was configured to listen on all IPs (port 80), but the virtual host configurations only applied to the actual IP for the domain (not localhost).

eg (freehand configuration, probably syntactically incorrect and missing irrelevant options): in httpd.conf: Listen 80

in domainA:80.conf: ServerName

Now, in the /etc/hosts file, it had this entry: localhost

what would happen when called out to on the same machine, it would use the localhost IP address. Therefore, instead of using the correct virtualHost configuration, it used the default configuration (this took me so damn long to figure out, but it makes perfect sense)

I don't really have a need to access the domains from localhost, so my question is: What's the best way to disable apache from trying to access the configuration using

1) Comment out the '' entry in /etc/hosts (this is what I did to fix it temporarily, but is this really a good solution)?

2) Update the httpd.conf file to listen only to the appropriate IP address (Listen ?

Sidenote: I went with option 1 temporarily because I use a Tenon configuration and was unsure of the ramifications of changing their default value on the 'Listen'

share|improve this question
up vote 3 down vote accepted

Your option 2 is the correct way to go. You'll probably find a Listen 80 statement in your httpd.conf which is saying listen on port 80 on all available interfaces. Changing it to Listen will restrict it to that address.

share|improve this answer
Lain, thanks for the response. Is there anything technically wrong with commenting out the entry in the hosts file? – DTest Dec 10 '10 at 19:05

Therefore, instead of using the correct virtualHost configuration, it used the default configuration (this took me so damn long to figure out, but it makes perfect sense)

If you are using name-based virtual hosts, this shouldn't be a problem. In this case, Apache matches virtual hosts to request based on the hostname of the request; the ip address doesn't matter. This only becomes a problem if you are using SSL (which in most cases requires address- or port-based virtual hosts).

Is there any particular reason you're listing these domains in the local hosts file? If other people are able to access your servers it suggests that you have the appropriate DNS in place. If you really want them in the local hosts file, you could put them there with their actual IP address rather than making the names aliases for localhost.

share|improve this answer is the only one in the hosts file, and only because that happens to be the 'hostname' the Mac Xserve was setup with. edit: also, I am using SSL on a couple of the domains. The biggest issue is we're using a pre-compiled admin called 'Tenon' (made for Mac OSX) and some of these things are legacy configurations. We've had issues before and are looking into scrapping it and compiling our own Apache/PHP. The reason we haven't previously is 'status quo' mostly works :D – DTest Dec 10 '10 at 18:57

Your Answer


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.