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'm trying to run Apache on OS X Mountain Lion but can only get the virtual host 'localhost' to work.

In /etc/hosts I have:       localhost broadcasthost
::1             localhost
fe80::1%lo0     localhost

In httpd-vhosts.conf I have:

NameVirtualHost *:80

<VirtualHost *:80>
        DocumentRoot "/Users/johnpeden/Sites/solas-lite"

<VirtualHost *:80>
        DocumentRoot "/Users/johnpeden/Sites/magento"

<VirtualHost *:80>
        ServerName localhost
        DocumentRoot "/Users/johnpeden/Sites"

Localhost displays exactly what I'd expect it to, and if I ping localhost, or I get a response from But, if I try to access or in a browser, I get no response. I can even map localhost to another folder and it works

Server has been restarted, computer has been restarted. Output of httpd -S is:

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server (/private/etc/apache2/extra/httpd-vhosts.conf:28)
         port 80 namevhost (/private/etc/apache2/extra/httpd-vhosts.conf:28)
         port 80 namevhost (/private/etc/apache2/extra/httpd-vhosts.conf:33)
         port 80 namevhost localhost (/private/etc/apache2/extra/httpd-vhosts.conf:38)

What is going wrong?

share|improve this question

closed as off-topic by Sven, Michael Hampton Oct 15 '14 at 3:15

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must be relevant to professional system administration. Server Fault is dedicated to professional system and network administrators. End user and enthusiast questions are off-topic (contact your system administrator or hire a professional to help you out). Please see the Help Center for more information." – Sven, Michael Hampton
If this question can be reworded to fit the rules in the help center, please edit the question.

So I've reverted to using MAMP in order to try and get some work done but now vhosts appear not to work at all. Could it be to do with the fact that I can access localhost but returns nothing. I have no idea why it wouldn't work, but the dev domains map to for sure, the problem is definitely vhosts not working. – jcpeden Dec 13 '13 at 22:29

Btw, I don't think this has anything to do with Mountain Lion, you'd see the same behavior on Linux, Windows, etc.

I think the issue here is that in your /etc/hosts the first entry for is localhost so if your browser is always coming from the local machine the http request will always say that it's coming from localhost or or magento-dev to which is in essence localhost according to the /etc/hosts file, then apache will interpret that the request is destined to the localhost NamedVirtualHost.

Have you tried making requests outside the machine where your are running apache.

I would also check your apache logs to see where the requests are coming from and see the request headers as well.

Hope this helps.

share|improve this answer
If that were the case, then surely everything would redirect to the localhost alias. Are you implying I can't setup multiple virtual hosts on my local machine? I've not made requests from an external machine to mine but will check the access logs now. – jcpeden Dec 12 '13 at 22:57
Ugh, just tried on a different network and the vhosts work perfectly...something to do with a weird setup on the work network changing my IP? – jcpeden Dec 12 '13 at 22:59
It's possible that your requests are coming from the IP address assigned to your interface and before they were coming from localhost or You can double check going back to your old setup and see the differences in the log. When you changed network did by any chance the content of your /etc/hosts file changed? Sometimes DHCP servers have DHCP options configured that will change configuration on the machine they are giving a DHCP address to. – Rico Dec 12 '13 at 23:14

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