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'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:

127.0.0.1       localhost magento.dev solas-lite.dev
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost

In httpd-vhosts.conf I have:

NameVirtualHost *:80

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

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

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

Localhost displays exactly what I'd expect it to, and if I ping localhost, solas-lite.dev or magento.dev I get a response from 127.0.0.1. But, if I try to access http://solas-lite.dev or http://magento.dev 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 solas-lite.dev (/private/etc/apache2/extra/httpd-vhosts.conf:28)
         port 80 namevhost solas-lite.dev (/private/etc/apache2/extra/httpd-vhosts.conf:28)
         port 80 namevhost magento.dev (/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 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 127.0.0.1 returns nothing. I have no idea why it wouldn't work, but the dev domains map to 127.0.0.1 for sure, the problem is definitely vhosts not working. –  jcpeden Dec 13 '13 at 22:29

1 Answer 1

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 127.0.0.1 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 127.0.0.1 or magento-dev to 127.0.0.1 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 127.0.0.1 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.