Networking

ERR_CONNECTION_REFUSED: What It Means and How to Fix It

ERR_CONNECTION_REFUSED means the computer at that address answered, but nothing was listening on the port the browser asked for, so the connection was rejected immediately. On your own machine it almost always means the dev server isn't running or is on another port; on a public site it means the site's server is down or misconfigured.

Chrome shows it as "This site can't be reached" with "host refused to connect." and the code ERR_CONNECTION_REFUSED. Internally Chromium lists it as error -102, "A connection attempt was refused."

What "refused" actually means

To open a page, the browser first makes a TCP connection to an IP address and port (80 for http://, 443 for https://, or whatever follows the colon, such as :3000). If the machine is reachable but no program is listening on that port, its operating system replies with a reset (RST), as the TCP standard requires for a segment that reaches a port with no connection, and the attempt fails at once. The Linux connect(2) man page defines the underlying error, ECONNREFUSED, as "no one listening on the remote address".

That makes refused different from the errors it gets confused with:

Chrome codeWhat happenedLook at
ERR_CONNECTION_REFUSED (-102)Host reached, nothing listening on the portIs the server running, right port, right address
ERR_CONNECTION_TIMED_OUT (-118)No answer at allFirewall dropping packets, host down, wrong IP
ERR_CONNECTION_RESET (-101)Connection opened, then cutServer crash, proxy, TLS or middlebox problem
ERR_NAME_NOT_RESOLVED (-105)Name never turned into an IPDNS, typo in the domain

Reproduce it from the command line

Testing outside the browser separates a browser problem from a network one. Each tool reports the same refusal in its own words. These are real messages from connecting to an unused port on the local machine:

ToolMessage
curl (Linux)curl: (7) Failed to connect to 127.0.0.1 port 5999 after 0 ms: Connection refused
curl (Windows)curl: (7) Failed to connect to 127.0.0.1 port 5999 after 2034 ms: Couldn't connect to server
Node.jsconnect ECONNREFUSED 127.0.0.1:5999
Python (Linux)ConnectionRefusedError: [Errno 111] Connection refused
Python (Windows)ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

On Windows, PowerShell gives a yes/no answer:

Test-NetConnection 127.0.0.1 -Port 5999

Look for TcpTestSucceeded : False. Against a remote site, use its host name and port, for example Test-NetConnection example.com -Port 443.

Fix it on localhost (your own dev server)

  1. Check the server is actually running. Look at the terminal where you started it. A crash on startup (a syntax error, a missing environment variable) often scrolls by and leaves nothing listening.
  2. Check the port. The URL must match the port the server printed when it started. Frameworks differ: 3000, 5173, 8000 and 8080 are all common defaults.
  3. Confirm something is listening. On Windows: Get-NetTCPConnection -LocalPort 3000 -State Listen. On macOS or Linux: lsof -i :3000. No output means nothing is listening there. If the port is taken by a different program, see how to fix "port already in use".
  4. Check the address it listens on. See the next section.

localhost, 127.0.0.1 and ::1

localhost can resolve to the IPv4 address 127.0.0.1 and the IPv6 address ::1. A server that listens only on 127.0.0.1 refuses connections to ::1, and the reverse is also true. Node.js is a frequent example: since Node 17 its DNS lookups return addresses in the order the system gives them (verbatim) instead of putting IPv4 first, so a client may try ::1 first. If http://127.0.0.1:3000 works and http://localhost:3000 does not, this is your cause. Use the IP in the URL, or bind the server to both addresses. More background is in what localhost is.

Docker, WSL and virtual machines

A server inside a container that listens on 127.0.0.1 is only reachable from inside that container. Make it listen on 0.0.0.0 and publish the port, for example docker run -p 3000:3000 .... Without -p, the host's port 3000 has nothing behind it and the browser gets a refusal. The details are in Docker port mapping.

Fix it on a public website

If one site refuses while everything else loads, the site's server or its front-end proxy is not accepting connections on that port. You cannot fix that from your side. A few checks are still worth doing:

  • Check the scheme and port in the URL. https://site:8080 or http:// versus https:// can hit a port that the site does not serve.
  • Try another network. Load the site on mobile data. If it works there, something on your network (a router rule, a company proxy or filter) is the problem.
  • Test with curl. curl -I https://example.com shows whether the refusal is specific to the browser.

When every site is refused

A refusal on every site points at something between the browser and the internet that is supposed to accept connections and isn't:

  • A proxy that is no longer running. If the system or browser is set to use a proxy at, say, 127.0.0.1:8888 and that program has closed, every request is refused by your own machine. Check the proxy settings in Windows or macOS network settings, and in the browser if it has its own.
  • A VPN or security tool. Some filter traffic through a local proxy. Disconnect or pause it briefly to test.
  • A firewall that rejects instead of dropping. A firewall rule that silently drops packets produces a timeout. A rule set to reject sends a reset, which looks exactly like a refusal. See what a firewall does.

If it still fails

Run curl -v against the exact URL and read the line after Trying: it shows the IP address and port actually attempted. If the IP is not the one you expect, the problem is name resolution or a stale entry in your hosts file, not the server. If the IP and port are right and the server's own machine shows nothing listening on that port, the server is the problem; restart it and check its logs for the startup error.

Frequently asked questions

Is ERR_CONNECTION_REFUSED my fault or the website's?
If it happens on one public website while others load, the problem is almost always on the site's side: its server or proxy is down or not listening. If it happens on every site, check your proxy, VPN and security software. If it happens on localhost, your own development server is not running or is on a different port.
What is the difference between ERR_CONNECTION_REFUSED and ERR_CONNECTION_TIMED_OUT?
Refused means a reply came back quickly saying nothing is listening on that port. Timed out means no reply came back at all, usually because a firewall silently dropped the packets or the host is unreachable. A refusal proves the machine was reached; a timeout does not.
Will clearing the browser cache fix ERR_CONNECTION_REFUSED?
Rarely. The refusal happens before any page data is exchanged, so cached files and cookies are not involved. It can help only when the browser is pinned to an old redirect, for example a cached redirect from http to an https port that nothing serves.
Why does localhost refuse but 127.0.0.1 work?
localhost can resolve to the IPv6 address ::1 as well as 127.0.0.1. If your server only listens on 127.0.0.1 and the client tries ::1 first, that attempt is refused. Use 127.0.0.1 in the URL, or make the server listen on both addresses.

Sources