Connection Refused Error
Getting "Connection refused" or "ERR_CONNECTION_REFUSED" when accessing localhost? This error means your browser cannot connect to the server. Here's how to fix it.
Common Causes
- Server not running - Apache/Nginx/Node.js not started
- Wrong port - Accessing wrong port number
- Firewall blocking - Security software blocking connection
- Port already in use - Another app using the port
- Service crashed - Server stopped due to error
Solutions
1. Start Your Web Server
# XAMPP
# Open XAMPP Control Panel
# Click "Start" next to Apache
# Linux Apache
sudo systemctl start apache2
sudo service apache2 start
# Nginx
sudo systemctl start nginx
# Node.js
node server.js
# Check if server is running
# Windows
netstat -ano | findstr :80
# Linux/Mac
sudo lsof -i :80
2. Verify Correct Port
# Default ports:
# http://localhost (port 80)
# http://localhost:8080 (port 8080)
# http://localhost:3000 (Node.js)
# http://localhost:8000 (Python)
# Check which port your server uses
# Look at server configuration or startup logs
3. Check Firewall
# Windows - Allow Apache
netsh advfirewall firewall add rule name="Apache" dir=in action=allow program="C:\xampp\apache\bin\httpd.exe"
# Linux - Allow port 80
sudo ufw allow 80/tcp
# Temporarily disable firewall to test
# Windows: Windows Security > Firewall > Turn off
# Linux: sudo ufw disable
Related URLs and Resources
- localhost not working
- localhost:80 - HTTP port
- localhost/xampp - XAMPP setup