Localhost Refused to Connect

Your browser reached your own computer, and no program was listening on that port. The fix is to start the server, or to open the port it is really on.

Updated November 2026 · 4 min read

The short version: "localhost refused to connect" (ERR_CONNECTION_REFUSED) means your computer answered and said no: nothing is listening on the port in the address. It is almost never a network or browser problem. Start your server, read the port it prints, and open that exact address with http://.

Error code
ERR_CONNECTION_REFUSED
What it means
No program is listening on that port
Whose side
Your own computer
Most common cause
The local server is not running

What "localhost refused to connect" means

When you open http://localhost:3000, the browser asks your own computer for a connection on port 3000. If a program is listening there, it answers. If none is, the operating system rejects the connection straight away, and the browser reports that localhost refused to connect.

That speed is the clue. A refusal comes back in milliseconds and means the machine is reachable and the port is closed. A firewall that silently drops traffic causes a long wait and a timeout, which is a different error.

The same error on a public website means that website's server is down or blocking you. That case is covered in the ERR_CONNECTION_REFUSED guide. This page is about your own machine.

Why localhost refuses the connection

  • The server is not running. By far the most common cause. The terminal was closed, the computer restarted, or XAMPP, WAMP or MAMP is open with Apache still stopped.
  • The server crashed on startup. A syntax error, a missing dependency or a failed database connection ended the process before it could listen.
  • It is on a different port. You opened localhost:3000 and the server chose 3001 because 3000 was busy. Plain http://localhost means port 80, which is rarely what a dev server uses.
  • It listens on a different address. A server bound to 127.0.0.1 does not answer on the IPv6 address ::1, and a server inside Docker bound to 127.0.0.1 does not answer the host at all.
  • The container port is not published. Without -p 3000:3000 (or a ports: entry in Compose) the port exists only inside the container.
  • Security software blocks the port. Rare for localhost, but some endpoint protection tools block local ports.

Check whether anything is listening

One command shows whether a program is listening on the port, and which one. No output means nothing is listening, and that is exactly when the browser says the connection was refused. The examples use port 3000: put your own port in its place.

Finding the program on port 3000 and stopping it. The process ID 48213 is an example: use the one your own command prints.

On Linux, ss -ltnp | grep :3000 gives the same answer. Add sudo on macOS or Linux to see programs owned by another user. Stopping a process ends whatever it was doing, so check what it is before you stop it.

How to fix it

Check the server

  1. Look at the terminal or control panel where the server runs. If you see an error or a prompt, it is not running.
  2. Start it again and read the output for the address, for example Listening on http://localhost:3001.
  3. In XAMPP, WAMP or MAMP, start Apache. If it stops again at once, another program (often IIS on Windows) holds port 80.

Check the address

  1. Open the exact address the server printed, including the port.
  2. Use http://. If the browser switches to https:// by itself, type the full address again with http:// in front.
  3. Try http://127.0.0.1:PORT in place of localhost. If that works, the server is listening on IPv4 only.

Check the port

  1. Confirm something is listening with the commands in the section above. No output means nothing is.
  2. From a terminal, run curl -I http://localhost:3000. "Connection refused" there too rules the browser out.
  3. In Docker, run docker ps and check the PORTS column shows a mapping such as 0.0.0.0:3000->3000/tcp. Make the app listen on 0.0.0.0 inside the container.

From localhost to production

On your laptop this error is harmless: you see it, you start the server, it goes away. On a live server the cause is identical, a process that stopped listening, but the people who see it are your visitors, and they do not tell you.

To test a deployed address by hand, the free bulk URL status checker shows the status code and redirects for a list of URLs, and Is Website Down checks one from several countries. Neither can see localhost: like any service on the internet, they only reach public addresses.

Deployed it? Watch the public URL.

Pulsetic is website uptime monitoring. It cannot reach localhost, but once your app is live it checks the public URL from outside your network, confirms any failure from another region, then emails you.

10 monitors free, checked every 5 minutes, with email alerts on failure and recovery. No credit card.

Sources and further reading

The documentation and specifications this guide is written from.

Frequently asked questions

  • What does "localhost refused to connect" mean?

    Your browser asked your own computer for a connection on a port where no program was listening, so the operating system rejected it. Start the server, or open the port it is really using.

  • Is it a problem with my internet connection?

    No. A request to localhost never leaves your computer, so your internet connection, router and DNS are not involved.

  • Why does 127.0.0.1 work when localhost does not?

    On many systems localhost resolves to the IPv6 address ::1 as well as 127.0.0.1. A server that listens on IPv4 only answers one and refuses the other. Use 127.0.0.1, or make the server listen on both.

  • Why does it happen only in Docker?

    Inside a container, localhost means the container itself. The app has to listen on 0.0.0.0, the port has to be published with -p, and one container reaches another by its service name, not by localhost.