Mac – Safari is unable to reach localhost (127.0.0.1)

localhostmacsafari

I've encountered a really strange Mac problem: Safari is unable to connect to localhost whereas all other applications can connect as normal (Firefox, Chrome, ping, etc.).

My /etc/hosts is the standard setup:

$ egrep localhost /etc/hosts
# localhost is used to configure the loopback interface
127.0.0.1   localhost
::1         localhost 
fe80::1%lo0 localhost
127.0.0.1   testing.localhost

Question: Have anyone else encountered this? What could be the problem?

Update #1: I have a server running on localhost:8080. When accessing from Safari I get the error message "Safari could not connect to the server". "http://localhost:8080/" works flawlessly in Firefox and Chrome.

Update #2: Same problem with "http://127.0.0.1:8080/" – so it does not seem to be related to resolving localhost to 127.0.0.1.

Best Answer

I think we need a little more information based on your question.

I'm going to guess you have a web server running to accept requests? I currently don't, and Safari won't connect to 127.0.0.1, because it "Couldn't find 127.0.0.1" - even though I can ping it just fine.

So first, you need to have something running. Secondly, have you tried connecting to testing.localhost with Safari, just incase the two entries are confusing Safari (this is entirely possible).

When you say "applications can connect as normal" with Chrome and Firefox, what are you seeing? The web page you're expecting to see? A different error?

Edit

I downloaded and installed MAMP, and I could not reproduce this error.

Some forum threads suggest IPv6 resolution is causing this issue. I would be inclined to turn off IPv6 and remove the entry from the hosts file (temporarily just for testing)

  1. Apple Menu > System Preferences
  2. Network
  3. Select your Network Connection > Advanced
  4. Configure IPv6 > Off

Apply, restart, and see how it goes.

Related Question