2

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, 127.0.0.1 works just fine, takes me to the /Sites on my username.

My .hosts file looks like that:

127.0.0.1 localhost
255.255.255.255 broadcasthost

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

  • Check httpd.conf, it may be divided in two or more vhosts which separate "localhost" & "127.0.0.1" – Pierre-Yves Gillier Sep 30 '09 at 13:33
  • Check vhosts.conf if exists. – lg. Sep 30 '09 at 14:12
  • 1
    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, 127.0.0.1, the computer's real IP, whatever). To get your Sites folder, you need to add ~yourshortname (e.g. 127.0.0.1/~konzepz). 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
7

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.

  • As I said, 127.0.0.1 results with my /Sites folder. Until yesterday, localhost got me right there. – konzepz Sep 30 '09 at 13:42
3

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
1

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.

1

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

1

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
  • this is the only solution fixed my problem – nikoss Oct 5 '17 at 8:19
0

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.

-1

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.

-2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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