curl: (7) Failed to connect to localhost port 80: Connection refused
curl: (7) Failed to connect to localhost port 80: Connection refused
DodaTech
2 min read
The error “curl: (7) Failed to connect to localhost port 80: Connection refused” means curl tried to reach localhost:80 but no process accepted the connection. This typically appears when testing a local Nginx setup.
What It Means
The curl command issued an HTTP GET request to http://localhost. The operating system responded with “Connection refused” because nothing is listening on TCP port 80. This is not a DNS or network issue — the connection was actively rejected at the transport layer.
Why It Happens
- Nginx is not installed or not running.
- Nginx is running but listening on a different port (e.g., 8080 or 443).
- Nginx is bound to a different interface (e.g.,
192.168.1.100) but you connected to127.0.0.1. - A firewall (UFW, iptables) is blocking port 80.
- Nginx configuration has a syntax error that prevented it from starting.
- The system’s web root is empty and Nginx failed to load the default server block.
How to Fix It
1. Check if Nginx is running
sudo systemctl status nginx2. Start Nginx if stopped
sudo systemctl start nginx
sudo systemctl enable nginx3. Test Nginx configuration syntax
sudo nginx -t4. Find which port Nginx is actually using
sudo ss -tlnp | grep nginx5. Allow port 80 through the firewall
sudo ufw allow 80/tcp
sudo ufw reload6. Test with the correct port
curl http://localhost:8080FAQ
Previous
curl: (60) SSL certificate problem: self signed certificate
Next
ERROR 1049 (42000): Unknown database
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro