
Your command fails with curl: (7) Failed to connect — sometimes with “Connection refused” appended. This cURL error 7 fix guide explains exactly what the code means: the TCP connection to the server never formed at all. DNS worked, the address was found, but nothing answered on the other end. That distinction matters, because error 7 has completely different causes — and fixes — than its DNS sibling (error 6) or its TLS siblings (errors 35 and 60). Updated for 2026.
Picture it as a phone call: error 6 means you could not find the number; error 7 means you dialled the right number and nobody picked up. The server might be down, a firewall might be blocking the port, you might be knocking on the wrong port, or a proxy might be refusing on the server’s behalf. The steps below find out which in order.
What Causes cURL Error 7
- Server down or unreachable: the service crashed, is under maintenance, or the machine is offline.
- Wrong port: connecting to a port where nothing listens (e.g. 443 on an HTTP-only server).
- Firewall blocking: a firewall dropping traffic to the target port — the most common infrastructure cause.
- Broken proxy configuration:
http_proxy/https_proxypointing at a dead or refusing proxy. - IP not whitelisted: the server (or registrar/API) only accepts connections from approved IPs.
- Service bound to localhost: the service listens on 127.0.0.1 only, unreachable from outside (classic Docker/containers gotcha).
- Network routing issues: no route to the host from your network.
How to Fix cURL Error 7: 7 Steps
Step 1: Verify the URL and port
Check for typos in the hostname and confirm the port: curl -v https://example.com shows exactly which IP and port cURL attempts. A missing port default (80 for HTTP, 443 for HTTPS) or an explicit wrong port (:8080 on a :80 service) is a frequent culprit.
Step 2: Confirm basic connectivity
Run ping example.com to check the host is reachable at all, and nslookup example.com to confirm DNS resolves. If ping fails entirely, the problem is network-level (routing, host down) rather than service-level. If DNS fails instead, see our cURL error 6 guide.
Step 3: Test whether the port is open
Use telnet example.com 443 or nc -zv example.com 443. If the port test fails but ping works, the port is closed or filtered — either the service is not running or a firewall blocks it. On the server itself, check what listens with ss -tuln | grep 443 or netstat -tuln | grep 443.

Step 4: Rule out the proxy
Check env | grep -i proxy — a stale http_proxy sends your request to a proxy that may be dead, and the refusal you see comes from the proxy, not the target. Bypass it for one test with curl --noproxy "*" https://example.com; if that works, fix or unset the proxy variables.
Step 5: Check firewalls on both ends
On your machine, confirm the local firewall allows outbound connections to the port. On the server, check iptables/ufw/cloud security groups for inbound rules on the port — open 80/443 as needed. If you manage the server through a panel (Plesk, cPanel), check its firewall module too. Remember to re-check after any change with the Step 3 port test.
Step 6: Verify the service is actually running
On the server, run systemctl status nginx (or apache2, or your app service) and check logs with journalctl -u nginx --since "1 hour ago". A crashed or failed-to-start service is the simplest explanation for “connection refused.” Also confirm the service binds to the right interface — 127.0.0.1:8080 is unreachable from other machines; bind 0.0.0.0:8080 for external access (Docker users: check port mappings with docker ps).
Step 7: Check whitelists and try plain HTTP
Some APIs and registrars only accept whitelisted IPs — confirm yours is approved. As a diagnostic, try plain HTTP if the server offers it: if port 80 connects but 443 refuses, the problem is the TLS termination layer, not the network. For TLS-specific failures after a successful TCP connect, see our cURL error 35 guide.
How to Prevent cURL Error 7
Monitor your services with uptime checks that alert on connection refusal, not just HTTP 500s — error 7 means the port went dark entirely. Document every firewall rule with a reason and review them quarterly; “temporary” blocks have a habit of becoming permanent. In deployment scripts, add a post-deploy port check (nc -z) so a service that failed to bind never ships silently. For scheduled API jobs, log the exact curl error code — 7 vs 6 vs 28 tells you instantly whether to call the network team, the DNS team, or the app team. A quick port check with a free network diagnostic tool confirms your endpoints stay reachable.
Conclusion
cURL error 7 means the TCP handshake never completed: verify the port, test it directly, rule out proxies and firewalls, and confirm the service is running and bound correctly. It is a network-reachability problem, not a certificate or DNS one — treat it as such and it resolves fast. For more command-line errors explained plainly, follow the KamiWeb blog.
