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 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?

share|improve this question

migrated from stackoverflow.com 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" & "127.0.0.1" –  Pierre-Yves 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
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
add comment

6 Answers

up vote 6 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, 127.0.0.1 results with my /Sites folder. Until yesterday, localhost got me right there. –  konzepz Sep 30 '09 at 13:42
add comment

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
add comment

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

share|improve this answer
add comment

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

share|improve this answer
add comment

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
add comment

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
add comment

Your Answer

 
discard

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.