Skip to content
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 to 127.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 nginx

2. Start Nginx if stopped

sudo systemctl start nginx
sudo systemctl enable nginx

3. Test Nginx configuration syntax

sudo nginx -t

4. Find which port Nginx is actually using

sudo ss -tlnp | grep nginx

5. Allow port 80 through the firewall

sudo ufw allow 80/tcp
sudo ufw reload

6. Test with the correct port

curl http://localhost:8080

FAQ

How do I check if Nginx is listening on all interfaces?
Run sudo nginx -T | grep listen. You will see all listen directives. listen 80 default_server; binds to all interfaces. listen 127.0.0.1:80; binds only to localhost.
Why does curl return 'Connection refused' but the browser shows a different error?
curl shows the raw TCP-level error. A browser may show a proxy error or a cached page. The root cause is the same — no web server is listening on port 80.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro