All ArticlesHosting2026-11-13T00:43:13+08:00

Website Loads Fine in Browser but curl Returns Connection Refused? Check the Listening Port

A site appears to work from a browser but curl or monitoring tools get connection refused, causing false alarms or missed outages. After reading, you can verify which ports and interfaces your web server actually listens on and why proxies or browser caches mask the real state.

Your monitoring fires a "connection refused" alert for port 443, you SSH in, open the site in your browser, and it loads perfectly. So you dismiss the alert. Hours later, real users start reporting downtime. What happened?

"Connection refused" from curl or a monitoring probe while a browser shows the page fine is one of the most common false-comfort scenarios in hosting support. It almost always means the web server is not listening where the probe expects it to, and something else (a cache, a CDN, a proxy, or your browser itself) is papering over the gap.

What "Connection Refused" Actually Means

When a TCP client sends a SYN packet to a port and the kernel responds with RST (reset), the client sees "connection refused." This is not a timeout. It is not a DNS failure. It means the operating system received the packet and actively rejected it because nothing is listening on that port for that address.

Three common causes:

  • The web server process is not running at all.
  • The web server is running but bound to a different port (e.g., 8080 instead of 80).
  • The web server is bound to a specific IP or to localhost (127.0.0.1) instead of all interfaces (0.0.0.0).

If you already know how to check whether Apache or Nginx actually started, the next step is verifying exactly which address and port the process is listening on.

Verify Listening Ports with ss or netstat

ss is the modern replacement for netstat on Linux. Run this as root or with sudo:

ss -tlnp

Flags: -t TCP, -l listening, -n numeric (no DNS resolution), -p show process name. Sample output format:

State   Recv-Q  Send-Q  Local Address:Port  Peer Address:Port  Process
LISTEN  0       511     127.0.0.1:8080      0.0.0.0:*          users:(("nginx",pid=1234,fd=6))
LISTEN  0       511     0.0.0.0:443         0.0.0.0:*          users:(("nginx",pid=1234,fd=7))
LISTEN  0       128     0.0.0.0:22          0.0.0.0:*          users:(("sshd",pid=800,fd=3))

Look at the Local Address column. In this example, port 443 listens on 0.0.0.0 (all IPv4 interfaces), so external connections work. But port 8080 listens on 127.0.0.1 only, meaning connections from outside the server get refused.

If your system still has netstat (common on older CentOS boxes), the equivalent:

netstat -tlnp

Same flags, same meaning. Either command gives you the ground truth about what is actually accepting connections.

Key Things to Look For

Bound to localhost only. If Local Address shows 127.0.0.1:80 or [::1]:80, the web server only accepts connections from the machine itself. Any external request, whether from curl on another machine, a monitoring probe, or a real visitor, gets refused. This is common when a reverse proxy setup is intended (e.g., Nginx in front of Apache on port 8080) but the front-end proxy is not running or not configured.

Bound to a specific IP that is not the one being queried. A server with multiple IPs might have Apache listening on 192.168.1.10:80 but not on the public IP 203.0.113.5:80. If DNS points to 203.0.113.5, external requests get refused even though the service is technically running.

Listening on a non-standard port. The web server might be on port 8443 instead of 443. A browser that previously visited the site might have a cached redirect or HSTS entry that sends it to the right port transparently. curl with no port override hits 443 and gets refused.

IPv4 vs IPv6 mismatch. If ss shows the server listening on :::443 (IPv6 only) but the DNS A record points to an IPv4 address, IPv4 clients get refused. Or vice versa. Check both 0.0.0.0 (IPv4 wildcard) and ::: (IPv6 wildcard) lines.

Why the Browser Showed It Working

Several things can make a browser appear to load a site that is actually unreachable on the expected port:

Browser cache. Browsers aggressively cache pages, stylesheets, images, and even full page renders. If you visited the site recently, the browser may serve the cached version without making a new TCP connection at all. You see the page, you assume the server is fine. Open DevTools, check the Network tab, and look for "(from cache)" or "(from disk cache)" entries. A hard refresh (Ctrl+Shift+R or Cmd+Shift+R) forces a real request.

CDN or reverse proxy. If the domain routes through a CDN or a load balancer, the browser connects to the CDN edge, not your origin server. The CDN may serve a cached copy even if the origin is completely down. Meanwhile, curl pointed directly at the origin IP bypasses the CDN and hits the actual server, revealing the refusal.

DNS pointing somewhere else. Your local machine might have a different DNS cache or /etc/hosts entry than the monitoring server. The browser resolves the domain to IP-A (which works), while the monitoring probe resolves to IP-B (which does not). Verify with dig or nslookup from both locations.

HSTS or saved redirects. If the browser previously received an HSTS header or a 301 redirect, it may silently rewrite http:// to https:// or add a port number. curl does not remember previous responses unless you explicitly follow redirects with -L.

Reproduce the Problem Properly with curl

To test what the monitoring probe sees, run curl from outside the server (or from the server itself if testing localhost binding):

Test the exact IP and port, bypassing DNS and CDN:

curl -vk https://203.0.113.5:443/ -H 'Host: example.com'

The -v flag shows the connection attempt. -k skips certificate verification (useful for testing connectivity, not security). The -H 'Host: ...' header tells the web server which virtual host to serve.

If this returns "connection refused" but curl https://example.com works, something between the domain and the origin (CDN, proxy, load balancer) is absorbing the request before it reaches your server.

To test from the server itself whether localhost binding is the issue:

curl -v http://127.0.0.1:8080/

If this works but curl -v http://YOUR_PUBLIC_IP:8080/ does not, the service is bound to localhost only.

Fixing the Bind Address

Where to change the bind address depends on your web server and whether a control panel manages it.

For Nginx, check the listen directive in your server block. listen 80; listens on all interfaces. listen 127.0.0.1:80; listens on localhost only. After changing, test config with nginx -t and reload.

For Apache, check Listen directives in the main config (typically httpd.conf or ports.conf depending on distro). Listen 80 binds all interfaces. Listen 127.0.0.1:80 binds localhost only.

For LiteSpeed, the listener configuration in the admin console or config XML controls which address and port it binds to.

Warning: If you are running a control panel like cPanel/WHM, Plesk, or similar, manual edits to web server configs may be overwritten on the next service restart or panel update. Check the panel's documentation for the correct way to change listener bindings. Some panels have specific include directories for custom configurations that survive restarts.

After making changes, re-run ss -tlnp to confirm the new binding took effect.

A Quick Verification Sequence

When you get a "connection refused" alert but the site seems to work in a browser, walk through this:

  1. Run ss -tlnp on the server. Confirm the web server process appears and note the exact address and port.
  2. Check whether it binds to 0.0.0.0 / ::: (all interfaces) or a specific IP / 127.0.0.1.
  3. From an external machine, run curl -vk against the server's public IP on the expected port with the correct Host header.
  4. Compare with curl -v against the domain name to see if DNS or a CDN layer changes the result.
  5. In the browser, hard-refresh and check DevTools Network tab for cached responses.
  6. If a firewall is in play, check iptables -L -n or nft list ruleset to rule out a DROP or REJECT rule on the port. (A firewall DROP causes a timeout, not "connection refused," but a REJECT rule does produce a refusal.)

The whole sequence takes under two minutes and eliminates guesswork. The most common finding in support scenarios: the web server is running but bound to localhost because it expects a reverse proxy in front of it, and that proxy either crashed or was never configured. The browser worked because it hit a CDN cache or a stale local cache.

Do not trust a browser page load as proof that a server is healthy. Trust ss and curl against the actual IP. They show you what the network sees, not what your cache remembers.