Skip to content

Troubleshooting guide

ERR_CONNECTION_REFUSED: how to fix it

Connection refused means the browser reached the machine, and the machine actively said no. The network works; nothing is accepting connections on that port.

3 min read10 sectionsUpdated

On this page

Key points

  • Refused is an active rejection, unlike a timeout, which is silence.
  • The most common cause is a stopped service or a wrong port.
  • A service bound to 127.0.0.1 refuses connections from everywhere else.
  • "localhost refused to connect" nearly always means your dev server is not running.

What the error means

Chrome opened a TCP connection and received a reset in response to its first packet. That tells you the IP address is reachable and no program is listening on that port, or a firewall is configured to reject. It narrows the search a great deal compared with a timeout.

Common causes

  • The web server is stopped or crashed.
  • Wrong port, such as a dev server on 3001 while you open 3000.
  • Bound to localhost only. A service listening on 127.0.0.1 is unreachable from outside, and in Docker, from outside the container.
  • A firewall set to reject.
  • A VPN or local proxy intercepting connections.
  • DNS pointing at an old server that no longer runs the site.

Diagnose it

On the server, check whether anything is listening and on which address. 0.0.0.0 means every interface, and 127.0.0.1 means local only.

bash
# Is anything listening on 443 or 3000?
sudo ss -ltnp | grep -E ':(443|3000)\b'

# Test from outside: refused, or timeout?
nc -vz example.com 443

# Is the service up, and why did it stop?
systemctl status nginx --no-pager
journalctl -u nginx -n 50 --no-pager

# Docker: is the port actually published?
docker ps --format '{{.Names}}  {{.Ports}}'

Fixes

As a visitor: check the address and port, disable any VPN or proxy, and try another network or a phone. If the site fails everywhere, the site is down.

As a site owner: start the service and read why it stopped. Bind to 0.0.0.0 if it must accept outside connections, particularly inside a container. Publish the port in Docker. Check firewall rules with ufw status and cloud security groups, and confirm DNS points to the current server.

For local development: make sure the dev server is running, and open the port it printed.

Catch it automatically

A TCP or HTTP uptime check from several regions tells you within a minute when connections begin to be refused, and tells you the difference between refused and timed out. Add a process supervisor so a crashed service restarts by itself, then alert on the restarts, since a service that keeps restarting is still broken.

Frequently asked questions

What is the difference between connection refused and timed out?

Refused is an immediate rejection: the host answered and nothing was listening. Timed out means no answer at all, often a firewall dropping packets or a host that is down.

Why does localhost refuse to connect?

Your local server is not running, or runs on a different port. Check the terminal where you started it.

Why can I reach it on the server but not from outside?

The service is probably bound to 127.0.0.1, or a firewall blocks the port.

Check it now, free

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.