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'm working with Mac's built in Apache, and everything was just great UNTIL - something went wrong. I think it's the .hosts file.

http://localhost results with "It works!" message, while any /[foldername] cannot be found. However, works just fine, takes me to the /Sites on my username.

My .hosts file looks like that: localhost broadcasthost

I'm not that familiar with how Apache works; what did I do wrong? Where should I look?

share|improve this question

migrated from Sep 30 '09 at 13:31

This question came from our site for professional and enthusiast programmers.

Check httpd.conf, it may be divided in two or more vhosts which separate "localhost" & "" – Pierre-Yves Gillier Sep 30 '09 at 13:33
Nope. Thanks for trying. – konzepz Sep 30 '09 at 13:37
Check vhosts.conf if exists. – lg. Sep 30 '09 at 14:12
I think we need more information. The default behavior of OS X's web server is to show the "It works!" as the default page no matter what address you use for it (localhost,, the computer's real IP, whatever). To get your Sites folder, you need to add ~yourshortname (e.g. From what you describe, you must've done some special configuration to get it to redirect to your Sites folder. So, the first question is, what did you do to make it work in the first place? – Gordon Davisson Oct 3 '09 at 2:13
up vote 7 down vote accepted

The page "It Works" is the default apache Vhost. If you are getting this, it has nothing to do with the hosts file.

Will need more information on the url you are trying to access and what you expect to happen.

share|improve this answer
As I said, results with my /Sites folder. Until yesterday, localhost got me right there. – konzepz Sep 30 '09 at 13:42

Look into /etc/apache2/httpd.conf and see if httpd-userdir.conf is included:

# User home directories
Include /private/etc/apache2/extra/httpd-userdir.conf
share|improve this answer

Apache treats ip addresses differently than resolved "name" addresses. The IP goes to whatever port is listening, and happily forward from there. Things like "localhost" are handled by the "VirtualHost" section of the config file, where Apache is told which folder is the "root" folder for the server described by that NAME.

So, if you've been happily using "localhost" and now that's not working, I'd look to see if something has changed in the VirtualHost section of your httpd.conf file.

share|improve this answer

Have you tried http://localhost/~[username] where [username] is the user you're currently logged in as?

share|improve this answer

It's possible you need to specify a port; you may find the right one in System Preferences.

As a pain-free alternative, you could download MAMP to use in place of OS X's built-in Apache.

share|improve this answer

Though my macports' apache installation had been running fine something recently changed and the OS X default apache was back in play today. So, I got the same, unexpected, "It Works!" that you did.

The fix was to unload the apache daemon from the system's launchd.

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
share|improve this answer

In Mac this is the only sentence written at index.html as shown below.

cat /Library/WebServer/Documents/index.html.en

It works!

So, that is the expected output.

share|improve this answer

OK. Httpd.conf file. ServerName should be - at least it is if your trying to use apache to serve a ruby on rails application. Hope this helps

share|improve this answer

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.