Safari cannot connect to localhost but can connect to 127.0.0.1

21,040

You probably installed something on your machine that acts as a web server and uses HTTP Strict Transport Security (HSTS) to make sure your browser knows it should always use TLS (HTTPS) when connecting. Then you connected to it by pointing your browser at localhost, and now your browser believes it should only use HTTPS when connecting to localhost.

Apparently Safari stores its list of HSTS websites in ~/Library/Cookies/HSTS.plist, so you should be able to fix it by editing that plist file to remove the entry for localhost, or by deleting that plist altogether if you don't mind resetting the whole list of sites Safari has learned to strictly require TLS for.

Share:
21,040

Related videos on Youtube

The Kid From Yesterday
Author by

The Kid From Yesterday

Just a teen trying to learn to program and wanting to change the computer industry!

Updated on September 18, 2022

Comments

  • The Kid From Yesterday
    The Kid From Yesterday almost 2 years

    For some reason, all of a sudden my Safari cannot connect to localhost because it cannot establish a secure connection. However, it is able to connect 127.0.0.1. Oddly enough Firefox is able to connect to localhost and 127.0.0.1. I believe it's some sort of certificate issue, but that's just a guess. What can I do so I can connect to localhost on Safari again?

    Thanks

  • The Kid From Yesterday
    The Kid From Yesterday over 7 years
    I think this is the solution, but the only problem is that it keeps adding the localhost entry after I start Safari. Even if I delete the plist.
  • The Kid From Yesterday
    The Kid From Yesterday over 7 years
    Deleted this plist and restarted and this worked thank you so much!