Localhost not working in Chrome, 127.0.0.1 does work
Asked Answered
D

11

65

I'm trying to run a local node server, but for whatever reason localhost:3000 does not work. The error page states This webpage is not available ERR_CONNECTION_CLOSED However, 127.0.0.1:3000 does work. I have tried making changes to my hosts file, but to no avail. Does anyone have any idea what's causing the problem?

Chrome version is 46.0.2490.80 m

Damien answered 4/11, 2015 at 14:49 Comment(2)
This solution worked for me here: superuser.com/a/1423344/644358Victor
Old post but I found the answer here. It explains everything.Acton
D
76

Here are the steps I took to make this work correctly:

  1. Edited my hosts file so 127.0.0.1 localhost. was present, and saved the file
  2. Cleared my Chrome cache, specifically cookies and cached files
  3. Cleared host cache in chrome://net-internals/#dns
  4. Restarted chrome

Alternatively, this also works:

  1. Navigate to chrome://net-internals/#hsts
  2. Under "Delete domain", type localhost and delete

Unbeknownst to me, my project had an HSTS middleware that set an HSTS cookie

Damien answered 4/11, 2015 at 15:31 Comment(3)
Was searching so long and had no idea what I did to cause this. For anyone coming in from Google, this happened to be by using react-aad-msal package and running a killall command on it when it froze while loading. This fixed it for me completely.Gonium
The alternative solution works for meFanchon
Alternative solution also works hereOsmose
B
18

I ran into a similar issue on my MacBook but none of the existing answers worked. I even tried the nuclear option and did a factory reset on my computer.

The issue turned out to be coming from the AirPlay receiver listening on Ports 5000 and 7000, which was creating the 403 error when I tried to serve something at localhost:5000.

The solution, as detailed here, was to uncheck AirPlay Receiver in System Preferences > Sharing

Banshee answered 5/12, 2021 at 22:23 Comment(3)
This! Thank you so much, what a weird port choice by Apple.Heathenish
The only thing that worked for me considering I have a MacBook tooBale
You're my life-saver. Thanks mate, I got the same problem in MacBookPro.Ilysa
P
10

For me (I had HTTP and HTTPs dev server on same port)

  • Chrome Dev tools F12
  • Application tab
  • Clear storage sub-tab
  • "Clear site data" button
Pathless answered 3/8, 2019 at 9:27 Comment(2)
nvm, thought it worked, still didn'tPiddle
Didn't work for me.Ilysa
T
8

I solved my problem by:

  • opening the developer console F12
  • Going to network tab
  • Check Disable Cache
  • Browse locahost
Tysontyumen answered 20/9, 2018 at 9:11 Comment(1)
Surprisingly, this worked, but the the "Clear Site Data" option in the DevTools Application Tab did not. Isn't this also deleting cached site information? Anyways, thanks mate, that problem gave me regular headaches :)Revealment
G
6

What you can do is go to Chrome setting > Privacy and Settings > See all the cookies and site data, search for localhost and delete it. Then refresh your site it will be working.

Regards

Gaseous answered 27/2, 2021 at 9:1 Comment(1)
It worked for me with the opposite problem, i.e. localhost was working while the 127.0.0.1 address didn't.Oversew
G
4

follow these steps.

  1. open chrome
  2. go to setting
  3. Privacy and security
  4. Clear browsing data
  5. check cookies and other site data
  6. click clear data.
Grueling answered 20/8, 2020 at 10:7 Comment(0)
C
3

if you're using a proxy there's a checkbox to bypass it for local addresses.

Cargo answered 19/12, 2017 at 12:51 Comment(0)
P
3

I had same issue and I cleared cookies and cache and it worked

enter image description here

Punke answered 20/7, 2020 at 2:28 Comment(0)
C
1

Go to Setting/clearBrowserData and just check all of history, cookies and cached files.

Carrew answered 22/8, 2021 at 5:4 Comment(0)
M
1

For me, Browse in Private (Ctrl + Shift + N) was enough.

Motion answered 11/8, 2022 at 22:2 Comment(1)
This worked for me too (Chrome on Mac)Bussy
P
-1

Finally I have solved this problem

  1. For those who have tried the clearing the cache from the browser and still facing the same issue follow these steps
  2. search for live server(ctrl+shift+x) you will find a settings icon. click on Extension settings
  3. you can find Live server>Settings:Chrome Debugging Attachment click on edit in Settings.json
  4. just add this (if there are multiple lines make sure to add comma[,]) "liveServer.settings.port": 0
  5. Doing This It will randomly pick an opened port each time.
Pedropedrotti answered 27/2, 2021 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.