localhost Refused to Connect: How to Fix ERR_CONNECTION_REFUSED
Work through this checklist in order. Most cases are a server that is not running or the wrong port.
"localhost refused to connect" means your browser reached your computer, but no program was listening on that port. Follow the checks below in order. Most cases are fixed by the first or second one.
Checks to try, in this order
- Is the server running? Look at the terminal where you started it. If it stopped or you closed it, start it again.
- Is it the right port? The terminal usually prints the address, such as
http://localhost:5173. Use exactly that. - Use http, not https, unless you set up a certificate.
- Try 127.0.0.1 instead of localhost. Some systems send localhost to IPv6 while the server listens only on IPv4, or the other way round.
- Check that something listens on the port. Use the tool below.
- Docker? The container needs a port mapping like
-p 8080:80, and the app inside must listen on 0.0.0.0, not only 127.0.0.1. - Still nothing? Turn off a VPN or proxy for a moment, and check your firewall.
Find what is using port 3000
Run these in a terminal on your computer. Nothing is sent to this site.
Related problems and fixes
- Works in one browser but not another
- Clear that browser’s cache for localhost, and check for a proxy or extension.
- Only fails on another device
- localhost always means the device you are on. See how to open localhost from your phone.
Questions about Refused to connect
- What does "localhost refused to connect" mean?
- Your browser reached your computer, but nothing was listening on that port. The server is stopped, or the port is wrong.
- Is localhost refused to connect a firewall problem?
- Rarely. It is usually a stopped server or a wrong port. A firewall more often causes timeouts than refusals.
Free tools that help
- Common ports listSearch a list of common TCP and UDP port numbers: SSH 22, HTTP 80, HTTPS 443, MySQL 3306, PostgreSQL 5432 and more, with dev server ports.
Config generators for this
- Apache virtual hostHost a website from a folder with Apache, with or without .htaccess.
- systemd service fileRun your app in the background and start it automatically at boot.