Find out why your server is refusing connections

ERR_CONNECTION_REFUSED is Chrome's error when something at your site's address answered but turned the connection down, so the page says the site refused to connect. Something at that address is reachable; what's missing is a program accepting connections on the port the browser used, 443 for HTTPS or 80 for HTTP. Either no web server is listening there, a firewall is rejecting the traffic, or DNS points at a different machine that doesn't serve your site.

Why a server refuses connections

  • The web server isn't running

    If the web server stopped, crashed or failed to start after a reboot or a deploy, nothing holds the port open. The operating system then answers each new connection on that port with a refusal.

  • It listens on a different port

    A server set up on port 8080 or 3000 refuses visitors who arrive on 80 or 443. The same thing happens when HTTP works on port 80 but nothing was ever set up to answer HTTPS on 443.

  • It listens only on the loopback address

    A server bound to 127.0.0.1 or localhost accepts connections from its own machine and refuses everything arriving on the public address. That's the right setup for an app behind a local proxy and the wrong one for a server visitors reach directly.

  • A firewall rejects the traffic

    A firewall rule that rejects with a TCP reset or an ICMP port unreachable message, rather than silently dropping the traffic, sends a refusal back to the browser. A rule that drops the traffic shows up as a timeout instead, and one that rejects with a prohibited message can show up as ERR_ADDRESS_UNREACHABLE in Chrome.

  • DNS points at the wrong machine

    If the record still holds the address of an old server, the machine at that address can refuse because it no longer runs your site. Compare the address the name resolves to with your server's.

net_error_list.h defines this error as a connection attempt that was refused. RFC 9293 says an attempt to open a TCP connection fails when the other end answers with a reset or an ICMP port unreachable message, and section 3.5.2 has a host answer a connection request that matches nothing open with that reset. The iptables-extensions manual lists the reject types a firewall can answer with, Linux's icmp.c turns a prohibited message into a host unreachable error, and net_errors_posix.cc maps that error to ERR_ADDRESS_UNREACHABLE. Chrome's error guide describes it as the page not letting Chrome connect.

Test the port from outside, then on the server

# From your own computer: does anything accept connections on 443?
nc -vz yoursite.com 443

# The same test with curl; exit code 7 means it couldn't connect
curl -sS -o /dev/null https://yoursite.com/; echo "exit $?"

# On the server (Linux): which programs listen on 80 and 443, and on which address?
sudo ss -ltnp | grep -E ':(80|443)\s'

Read what the port tests show

  • If ss lists nothing on port 443, no web server is listening there. Start it, then read its error log for why it stopped or never started. If it lists the port only on 127.0.0.1 or [::1], the server accepts connections from itself alone; change its listen address to 0.0.0.0, [::] or the server's public address. The ss manual explains each option used above.

  • If the server listens on the public address and nc from your computer still says the connection was refused, something between you and the program is rejecting it: the server's own firewall, a network firewall at your host, or a different machine answering because your DNS record points elsewhere, which dig +short on your domain will show. curl's error list defines exit code 7 as a failure to connect to the host.

How to fix a refused connection

  1. Start the web server and keep it runningStart the service, then find out from its log why it stopped. Set it to start at boot and to restart after a crash, so one failure or a reboot doesn't leave the port closed.
  2. Listen on the right port and addressMake the server listen on 443 for HTTPS and 80 for HTTP, on its public address or on all addresses. If your app listens on another port, put a web server or proxy in front of it on 443.
  3. Open the port in every firewallAllow inbound connections on 80 and 443 in the server's own firewall and in any network firewall or security group your host provides. If a CDN connects on visitors' behalf, allow its addresses too.
  4. Point the domain at this serverMake the A record, and the AAAA record if you publish one, hold this server's current address. Then repeat the nc test from outside to confirm the connection opens.

Frequently asked questions

Why does the site work on the server but refuse visitors?

The server is probably listening on 127.0.0.1 only, or a firewall rejects outside traffic. A test like curl http://localhost on the server goes to the loopback address, which a 127.0.0.1-only server accepts and which network firewalls never see, so it succeeds while visitors are refused. Compare the addresses ss -ltn lists with the address visitors use.

Is a refused connection the same as a timeout?

No. A refusal comes back right away, because a host at that address answered and turned the connection down. A timeout means nothing answered at all, which points to a server that's offline or a firewall that drops traffic silently. The guide to timed-out connections, linked below, covers that case.

What do visitors see when a CDN sits in front of the server?

Not this error, since their browser connected to the CDN without trouble. The CDN shows its own error page instead, such as Cloudflare's error 521 for an origin that refused the connection, and the fix on your server is the same.

How do I find out when the web server stops?

A web server that doesn't come back after a reboot keeps refusing every visitor until someone notices and starts it by hand. SiteCMD requests your home page every few minutes once you add the site, and it emails you when the site goes down and again once it recovers.