Guide

Localhost refused to connect on Mac? Fix it

The browser says “localhost refused to connect” or ERR_CONNECTION_REFUSED. That means nothing answered on that port: the request reached your Mac and found no server there. Here’s how to find out why in under a minute.

By Anmol Sethi · Updated

In short

Nothing is listening on that port. Run lsof -nP -iTCP -sTCP:LISTEN to see what is: usually the dev server crashed, or it started on a different port (3001 instead of 3000) because the first one was taken. If it’s listening only on [::1] or only on 127.0.0.1, open localhost rather than the IP. In Docker, publish the port with -p and make the app listen on 0.0.0.0. Portlivo shows every listening server and its port in the menu bar, so you can see at a glance which port to open.

Ask AIChatGPTClaudePerplexityGoogle AIGrok

1. Is anything listening on that port?

Ask macOS directly, using your port:

lsof -nP -iTCP:3000 -sTCP:LISTEN

No output means nothing is listening, and that’s the whole problem. Go back to the terminal that runs your server: it probably stopped with an error (a syntax error, a missing .env value, a failed install). Fix that and start it again.

To see every server running on your Mac at once:

lsof -nP -iTCP -sTCP:LISTEN

lsof only shows your own processes. A server started with sudo, or by another user such as postgres, needs sudo lsof -nP -iTCP -sTCP:LISTEN.

2. Is it on a different port?

Many dev servers quietly move to the next free port when theirs is taken: Vite goes from 5173 to 5174, Next.js from 3000 to 3001. Create React App asks first. The terminal prints the real address, so read the line that starts with Local: and open exactly that.

  ➜  Local:   http://localhost:5174/

If an old copy is holding the usual port, stop it (how to kill a port) and restart your server so it gets its normal port back. To pick a port on purpose, see how to change the port.

3. localhost vs 127.0.0.1 (IPv4 and IPv6)

On a Mac, localhost means two addresses: ::1 (IPv6) and 127.0.0.1 (IPv4). A server can listen on just one of them. Look at the NAME column in the lsof output:

lsof showsListens onWhat works
127.0.0.1:3000IPv4 onlylocalhost and 127.0.0.1
[::1]:3000IPv6 onlylocalhost and [::1], but not 127.0.0.1
*:3000Every address, the network tooEverything, including your phone

Browsers, curl and current Node try both addresses, so http://localhost:3000 is the safe choice. The trap is a hard-coded 127.0.0.1 (in a proxy setting, an .env file or a mobile app) talking to a server that only listens on [::1]: that is refused. Either use localhost there, or start the server on IPv4, for example vite --host 127.0.0.1.

4. http or https?

Most dev servers speak plain http. Typing https://localhost:3000 against one gives an SSL error, and the reverse gives an empty or broken page. Check the scheme in the address the terminal printed. If the browser keeps switching to https by itself, clear the site from its history or open the address in a private window.

5. Running in Docker?

A container’s ports are private until you publish them. Check the PORTS column:

docker ps --format "table {{.Names}}\t{{.Ports}}"
  • No 0.0.0.0:3000->3000/tcp (or similar) means the port isn’t published. Add -p 3000:3000 to docker run, or ports: ["3000:3000"] in Compose.
  • Published but still refused? The app inside the container is probably listening on 127.0.0.1, which is the container’s own loopback. Make it listen on 0.0.0.0, for example next dev -H 0.0.0.0, vite --host or flask run --host=0.0.0.0.
  • “Port is already allocated” instead? That’s a different problem: see the Docker port guide.

6. Opening it from your phone or another computer?

localhost on your phone means the phone itself, so it will always refuse. Use your Mac’s network address and a server that listens on the network: how to open localhost on your phone has the steps.

Is it the firewall?

Almost never for localhost. The macOS firewall filters connections from other devices, not ones your Mac makes to itself. If localhost works on the Mac but your phone can’t connect, then check System Settings → Network → Firewall, and allow your runtime (node, python) when macOS asks.

The one-click way: Portlivo

Portlivo lists every server listening on your Mac in the menu bar, with its project name and port, and checks each web server so one returning errors shows red. You can see straight away that your app started on 3001, or that it isn’t running at all, and open the right address in one click.

The inspector also says whether a server is bound to this Mac only or to every network address, which answers the phone and Docker questions above. From Terminal, portlivo ports prints the same list.

Questions people ask

What does ERR_CONNECTION_REFUSED mean on localhost?
Your Mac received the request, but no program was listening on that port, so it was turned away. It is not a network or internet problem: start the server, or open the port it really uses.
Why does 127.0.0.1 fail when localhost works?
The server listens only on the IPv6 address ::1. localhost covers both IPv6 and IPv4, but 127.0.0.1 is IPv4 only. Use localhost, or start the server on 127.0.0.1 explicitly.
It worked yesterday and now it’s refused. What changed?
Usually the server isn’t running: the terminal was closed, the Mac restarted or the process crashed. Run lsof -nP -iTCP -sTCP:LISTEN and start it again. If the usual port is now taken by an old copy, stop that first.

Try Portlivo free for 7 days. Every feature, no account.Then $8.99 once, no subscription.

Download for Mac

Still have a question?

Write to us — a real developer reads every email and replies personally.

support@portlivo.com