Guides

8 min readUpdated

ERR_CONNECTION_REFUSED: why a site refused to connect and how to fix it

Quick answer

ERR_CONNECTION_REFUSED is Chrome's error for a connection the other side actively rejected: the address answered, but nothing accepted a connection on that port, so the browser received a TCP reset instead of a page. Chrome shows it as "example.com refused to connect". On a public website it usually means the web server is stopped, listens on another port or address, or a firewall rejects the connection. On localhost it almost always means the development server is not running on that port.

01What does ERR_CONNECTION_REFUSED mean?

Chrome draws the page itself, under the heading "This site can't be reached", with the line "example.com refused to connect" and the code ERR_CONNECTION_REFUSED underneath. In Chromium's list of network errors it is error -102, described simply as "A connection attempt was refused". No HTTP request was sent and no server software produced a page, so there is no status code, no cookie and no cache entry involved.

At the network level the browser sent a TCP connection request (a SYN) to the address and port, and got a reset back. The TCP standard has a closed port answer that way, and a firewall rule that rejects rather than drops a packet produces the same result. The answer comes back almost instantly, which is the quickest way to tell a refusal from a timeout.

Other browsers name it differently. Firefox shows "Unable to connect" with "Firefox can't establish a connection to the server at example.com". Safari says it "can't connect to the server". Microsoft Edge is built on Chromium and shows the same ERR_CONNECTION_REFUSED code.

02Which message do you see?

The wording depends on the browser or tool, but these messages all describe the same refused connection. Match yours, then jump to the section for your situation.

MessageShown byRead next
example.com refused to connect. ERR_CONNECTION_REFUSEDChrome, Edge and other Chromium browsersYour side or theirs, then the fixes below
localhost refused to connect.Chrome, during local developmentlocalhost refused to connect
Unable to connect. Firefox can't establish a connection to the server at ...FirefoxVisitor fixes
curl: (7) Failed to connect to example.com port 443 after 0 ms: Couldn't connect to servercurl, exit code 7 (wording as printed by curl 7.88.1)Owner checks
connect: Connection refused, or Connection refusedssh, older curl versions and most command-line toolsOwner checks
TcpTestSucceeded : FalsePowerShell Test-NetConnection on WindowsOwner checks

03Is the problem on your side or the website's?

Answer this before changing any settings. Open the same address on another device that uses a different network, for example a phone on mobile data with Wi-Fi switched off. If the site loads there, the refusal is caused by something on your device or network. If it fails there too, the website is refusing connections and only its owner can fix it.

A refusal that affects only you usually has one of three causes: a security tool or VPN that rejects the connection locally, a hosts file entry or stale DNS answer that sends you to the wrong address, or a firewall on the site's server that has blocked your address, for example after too many failed logins. The last one is invisible to you except that the site works everywhere else.

04How to fix ERR_CONNECTION_REFUSED as a visitor

Work through these in order and reload after each one. Clearing the browser cache rarely helps here, because no page was ever loaded.

  • Check the address: a port number such as :8080 at the end, or https:// on a site that only serves http://, is refused if nothing listens there.
  • Wait a minute and reload: a web server that is restarting refuses connections for a few seconds.
  • Turn off the VPN, proxy or filtering DNS service, then reload.
  • Pause the web protection in your antivirus or firewall software and test again.
  • Look for the domain in your hosts file (C:\Windows\System32\drivers\etc\hosts on Windows, /etc/hosts on macOS and Linux); a line pointing it at 127.0.0.1 makes your own computer refuse it.
  • Flush the DNS cache (ipconfig /flushdns on Windows; sudo dscacheutil -flushcache followed by sudo killall -HUP mDNSResponder on macOS) in case you still resolve an old server address.
  • If the site fails on mobile data as well, tell the owner the time and the exact message; nothing on your side will fix it.

05"localhost refused to connect": fixing it in development

On your own machine the cause is nearly always that nothing listens on the port you opened. The development server is not running, crashed on start, or picked a different port because the usual one was busy; read the terminal where you started it before anything else.

The second cause is the address family. localhost can resolve to the IPv4 address 127.0.0.1 or the IPv6 address ::1, and a server that listens only on one of them refuses connections made to the other. Node.js has returned addresses in the order the system resolver gives them since version 17, which is often ::1 first, so a server bound to 127.0.0.1 and a client that asks for localhost can miss each other. Test both addresses explicitly, and make the server listen on the one your client uses, or on both.

Inside Docker, the application must listen on 0.0.0.0 within the container, and the port must be published with -p (for example -p 8080:80) for the host to reach it. A container port that is not published is refused on the host, however healthy the application is.

Find what is listening, then test each address (replace 3000 with your port)
# Linux: listening TCP sockets and the process that owns each one
ss -ltnp | grep ':3000'

# macOS
lsof -nP -iTCP:3000 -sTCP:LISTEN

# Windows (PowerShell)
Get-NetTCPConnection -LocalPort 3000 -State Listen

# test IPv4 and IPv6 separately
curl -v http://127.0.0.1:3000/
curl -v 'http://[::1]:3000/'

# Docker: which container ports are published to the host
docker ps --format '{{.Names}}  {{.Ports}}'

06How site owners find what refuses the connection

Test from the inside out, and from outside your own network for the final check. A refusal on the server itself means nothing listens on that port; a refusal only from outside means a firewall rule or the wrong listening address.

ResultMeaningNext step
Nothing listens on 443 in step 1HTTPS was never configured, or the server failed to startRead the service log; fix the error nginx -t reports
Listens on 127.0.0.1:443 onlyThe service is bound to the loopback addressChange the listen address to the public interface or 0.0.0.0
Refused from outside, works on the serverA firewall rule rejects remote connectionsAllow the port, or remove the block on the visitor's address
Refused for one visitor onlyThat address is banned, often by fail2banCheck the ban list before changing anything else
Works by IP, refused by nameDNS points at an old or wrong serverCompare the A and AAAA records with the server's addresses
Read-only checks for a public site (replace example.com and 203.0.113.10)
# 1. on the server: does anything listen on 80 and 443, and on which address?
ss -ltnp | grep -E ':(80|443)\b'

# 2. is the web server running, and does its configuration load?
systemctl status nginx
nginx -t

# 3. from outside: connect straight to the server's address with the real name
curl -sv -o /dev/null --resolve example.com:443:203.0.113.10 https://example.com/

# 4. Windows client: test the TCP port alone
Test-NetConnection example.com -Port 443

# 5. look for reject rules (nftables, or iptables on older systems)
nft list ruleset | grep -i reject
iptables -S | grep -i reject

07Common server-side causes and how to fix them

Most refusals follow a change: a configuration edit that stopped the web server from restarting, a migration that left DNS pointing at the old host, or a new firewall rule. Check what changed last before anything else.

fail2ban deserves a special mention because it is so often the answer to "it works for everyone but me". Its standard iptables actions reject banned addresses rather than dropping them, so a site owner who mistyped a password a few times sees an instant refusal while everyone else gets through.

  • Web server stopped after a failed reload: run nginx -t or apachectl configtest, fix the error, then start the service
  • No listener on 443: add the HTTPS server block and certificate, or stop linking to https:// until it exists
  • Wrong listen address or port after a change: compare the listen directives with ss -ltnp
  • Reject rules in nftables, iptables or a host firewall: allow 80 and 443 for the visitors who should reach the site
  • Stale DNS after a move: update the A and AAAA records, and remove AAAA records for a server that does not listen on IPv6

08ERR_CONNECTION_REFUSED behind a CDN or WAF

When a site sits behind a reverse proxy such as a CDN or a web application firewall, visitors connect to the proxy's edge, not to your server. A refused connection in the browser then means DNS no longer points at the edge, or the problem is on the visitor's side. An origin that refuses the edge shows up differently: as a 502 Bad Gateway or a provider code such as Cloudflare's error 521, which its documentation describes as the origin refusing connections from Cloudflare.

That split is also useful for security. Once a proxy is in front, the origin should accept connections on 80 and 443 only from the proxy's published addresses and refuse or drop everything else, so attackers cannot bypass the edge by connecting to the server directly. How to do that without breaking the site is covered in how to hide your origin IP.

Questions

Frequently asked questions

01Is ERR_CONNECTION_REFUSED my fault or the website's?
Test the site on another network, such as a phone on mobile data. If it fails there too, the website is refusing connections and only its owner can fix it. If it works there, the cause is on your side: a VPN, proxy, security software, a hosts file entry or an outdated DNS answer, or a block on your IP address at the site's firewall.
02Why does localhost refuse to connect?
Because nothing is listening on that port on your machine. The development server is not running, crashed, or started on a different port. If it is running, check the address family: a server that listens only on 127.0.0.1 refuses connections to ::1, and localhost can resolve to either. In Docker, the port also has to be published with -p.
03What is the difference between ERR_CONNECTION_REFUSED and ERR_CONNECTION_TIMED_OUT?
A refusal is an immediate answer: the address responded and rejected the connection, usually because nothing listens on the port or a firewall rule rejects it. A timeout means there was no answer at all, because the host is down, unreachable, or a firewall silently drops the packets. A refusal comes back in milliseconds; a timeout takes many seconds.
04Can a firewall cause ERR_CONNECTION_REFUSED?
Yes, if the rule rejects the connection instead of dropping it. A rule that answers with a TCP reset makes the browser report a refusal, while a rule that drops packets silently produces a timeout instead. Tools such as fail2ban reject by default in their standard iptables actions.
05Does clearing the browser cache fix ERR_CONNECTION_REFUSED?
Rarely. The error happens before any page is loaded, so cached files and cookies play no part. Flushing the DNS cache can help when you still resolve an old server address, and removing a hosts file entry helps when the domain is pointed at your own computer.

Sources

Sources and verification

The configuration and commands on this page are examples, not a tested recipe. Adapt them to your system and check them before use (nginx -t for nginx, nft -c -f for nftables, iptables-restore --test for iptables).

  1. 01net_error_list.h: CONNECTION_REFUSED (-102) · Chromium
  2. 02error_page_strings.grdp: error page headings and messages · Chromium
  3. 03RFC 9293: Transmission Control Protocol · RFC Editor
  4. 04curl exit codes · Everything curl
  5. 05Test-NetConnection · Microsoft Learn
  6. 06DNS module: dns.setDefaultResultOrder and verbatim ordering · Node.js
  7. 07Port publishing and mapping · Docker docs
  8. 08Error 521: web server is down · Cloudflare docs

Last updated