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 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 domainA.com

Now, in the /etc/hosts file, it had this entry: 127.0.0.1 localhost 127.0.0.1 domainA.com

what would happen when domainB.com called out to domainA.com 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 127.0.0.1?

1) Comment out the '127.0.0.1 domainA.com' 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 1.2.3.4 IP address (Listen 1.2.3.4:80) ?

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
add comment

2 Answers

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 1.2.3.4:80 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
add comment

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
    
domainA.com 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'...it mostly works :D –  DTest Dec 10 '10 at 18:57
add comment

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.