Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 have a few local versions of development websites on my local mac, and want to provide access to them from a browser through vhosts, as well as using the live (web) versions from time to time.

I have read many examples of people doing similar things by changing the URL, and having apache listen to the unique URL to serve from a local location. I have always done it using the same URL, but a different port, and while it works seamlessly on windows, I can't get it working on the mac.

(Let's say) I have two websites:


I want to access the local versions by using the same URL, by enabling the browser's proxy (with one click) which I have set to 8080. apache is set to Listen *:8080 in httpd.conf.

In httpd-vhosts.conf (which is getting loaded) I have:

NameVirtualHost *:8080

<VirtualHost *:8080>
    DocumentRoot "/Users/username/Development/Projects/amazingwebsite"

    <Directory "/Users/username/Development/Projects/amazingwebsite/">
        Options Includes Indexes Multiviews
        AllowOverride All
        Order allow,deny
        Allow from all


The '' vhost is basically the same - just different local location.

My /private/etc/hosts is now set to:

# Host Database
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##   localhost broadcasthost
::1             localhost 
fe80::1%lo0 localhost

and after an apache restart (web sharing off/on), apachectl -S reports:

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:8080                 is a NameVirtualHost
         default server (/private/etc/apache2/other/httpd-vhosts.conf:4)
         port 8080 namevhost (/private/etc/apache2/other/httpd-vhosts.conf:4)
         port 8080 namevhost (/private/etc/apache2/other/httpd-vhosts.conf:19)
Syntax OK

which looks ok to me.

The behaviour?:

  • => local installation (correct)
  • => times out (incorrect)
  • => quickly can't connect, browser can't find - (incorrect)
  • => goes to web version (correct)
  • => local installation (correct)
  • => times out (incorrect)
  • => browser can't find (incorrect)
  • => goes to web version (correct)

So my ServerAlias isn't working, or there is something wrong with my hosts file - or both!

I've spent ages on this, and could really do with some help - thanks..

share|improve this question
up vote 0 down vote accepted

The vhosts are working, you haven't written your local /etc/hosts correctly. What's happening is that your timeout-then-working is because a 'www.' lookup is most likely resulting in a real DNS CNAME pointer back to non-www. version.   localhost

That's how you use a hosts file - one IP listed one time, all aliases on the same line and you must list all subdomains needed, www. e.g. that will send traffic to your local Apache instance.

share|improve this answer
I tried this, and got no difference. Lots of tutorials on the web suggest the other way.. After looking at so many blogs on the subject, I can't even think how I got it working on the PC (turned off in another country right now). – DefenestrationDay Jul 6 '10 at 3:47
did you actually try it with the www. entries? regardless of other factors on implementation that's a key point in the setup and should be done. – troyengel Jul 6 '10 at 3:54
You're going to have problems with accessing both the local and the remote site due to DNS resolution conflicts. The /etc/hosts file is going to trump any other sort of DNS resolution. So, if you do set the www entries in your /etc/hosts, you're going to be able to access only the local installations. You're never going to be able to access both doing it this way. – photoionized Apr 8 '11 at 22:32

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.