Beamfar

Troubleshooting HTTP 502, 504, 522, SSL certificate, and DNS errors in production

When a client site fails in production, the first five minutes usually go to guessing which layer broke: registrar, DNS, CDN, reverse proxy, TLS certificate, or application runtime. Reading the exact error phase — DNS resolution, TCP connect, TLS handshake, or HTTP status code — narrows the root cause immediately so you fix the right system on the first attempt instead of restarting healthy servers.

Diagnose by connection phase first

Every external browser or probe request passes through four strict phases in sequence. A failure in an earlier phase means later layers were never even reached.

Failing phaseCommon error seen by visitorsReal layer at faultFirst check to run
1. DNS lookupDNS_PROBE_FINISHED_NXDOMAIN, SERVFAILDomain registrar expiry, broken nameservers, bad DNSSEC DS record, or deleted A/AAAA/CNAME recordRun a public DNS lookup and domain expiry check
2. TCP connectERR_CONNECTION_REFUSED, ERR_CONNECTION_TIMED_OUT, Cloudflare 522Origin firewall blocking edge IPs, crashed web server daemon, full disk, or network outageVerify web server process (nginx/caddy/apache2), port 80/443 firewall rules, and CDN IP allow-lists
3. TLS handshakeERR_CERT_DATE_INVALID, ERR_CERT_COMMON_NAME_INVALID, SSL_ERROR_BAD_CERT_DOMAINExpired Let’s Encrypt cert, broken HTTP-01 renewal behind redirect/WAF, or mismatched SNI vhostRun the SSL certificate checker to inspect issuer, SAN hostnames, and expiry
4. HTTP response502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout, 429, 520–524Crashed PHP-FPM/Node/Gunicorn upstream, exhausted database connections, slow query timeout, or WAF rate-limitingInspect proxy error logs (nginx/caddy) alongside application memory, CPU, and DB pool saturation

Check it now. The SSL certificate checker shows the issuer, the names, the expiry and the days left of a site’s certificate; the DNS lookup shows a domain’s A, AAAA, CNAME, NS and MX records. No account, and the address is not stored.

Exact triage playbooks for the five most common errors

1. HTTP 502 Bad Gateway

A 502 means your edge proxy (Nginx, Caddy, Apache, Cloudflare, or a load balancer) connected to the network successfully but received an invalid or closed response from the upstream application process.

  • WordPress / PHP stacks: Check whether php-fpm crashed from an out-of-memory kill (dmesg | grep -i oom), a fatal error right after a plugin update, or a mismatched Unix socket path (fastcgi_pass).
  • Node.js / Next.js / Python stacks: Check systemd / pm2 / container logs for crash loops after a recent deploy or missing environment variable.
  • Fast check: Compare the failure timestamp against your latest deploy or WordPress plugin update. If the proxy itself returns 502 in under 10 milliseconds, the upstream socket is dead rather than slow.

2. HTTP 504 Gateway Timeout (and Cloudflare 524)

Unlike a fast 502, a 504 or Cloudflare 524 happens when the upstream accepted the TCP connection but failed to send response headers before the proxy timeout (typically 30 to 100 seconds).

  • Database lock or pool exhaustion: A stuck migration, unindexed WooCommerce query, or unclosed connection pool stalls every incoming PHP/Node worker until the gateway gives up.
  • Synchronous third-party API call on page render: Calling an external payment, shipping, or webhook API without a tight client timeout (2–5 seconds) turns a vendor slowdown into a full storefront outage.
  • Fix pattern: Check slow-query logs and active worker counts (php-fpm status, pg_stat_activity, or upstream latency percentiles), restart wedged workers only after capturing stack traces, and add strict upstream timeouts.

3. Cloudflare 522 Connection Timed Out

A 522 means Cloudflare reached the edge normally but its TCP SYN packet to your origin server timed out before completing a handshake.

  • Cause A: A host firewall (ufw, iptables, fail2ban, or hosting security software) began rate-limiting or dropping Cloudflare edge IP ranges.
  • Cause B: Origin CPU or memory is pegged at 100%, or the web server stopped listening on port 443.
  • Fix pattern: Whitelist official Cloudflare IP ranges at the origin firewall, confirm the origin responds locally (curl -I http://127.0.0.1), and check whether an active DDoS or scraper burst saturated origin workers.

4. SSL / TLS Errors (ERR_CERT_DATE_INVALID and SAN mismatches)

Almost all modern certificate outages are renewal failures, not missing initial setup.

  • Why renewals break silently: A new redirect rule, Cloudflare proxy toggle, IPv6 AAAA record pointing to an old host, or aggressive WAF rule blocks /.well-known/acme-challenge/ 30 days before expiry. Nobody notices until day 0 when browsers display a full-screen security warning.
  • Wrong hostname (ERR_CERT_COMMON_NAME_INVALID): A site migrated to a new server without www in the certificate Subject Alternative Names (SAN), or the web server fell back to the default vhost certificate.
  • Fix pattern: Monitor certificate expiry at 30, 14, 7, and 1 day remaining, and inspect SAN names immediately after every domain or CDN cutover.

5. DNS Failures (NXDOMAIN and SERVFAIL)

DNS outages are the hardest to spot from inside the server because the origin host looks completely healthy while the outside world cannot reach it.

  • NXDOMAIN: Either the domain registration lapsed into registrar hold (clientHold / serverHold), or someone deleted the apex A/AAAA or CNAME record during a mail or hosting migration.
  • SERVFAIL: Commonly caused by changing nameservers while an old DNSSEC DS record remains published at the registrar, breaking cryptographic validation across recursive resolvers.
  • Fix pattern: Run a public DNS lookup from outside your office network, verify registrar status via RDAP, and keep DNS change history recorded next to every uptime check.

How Beamfar helps

Beamfar separates DNS, TCP connect, TLS handshake, redirect chain, and HTTP status on every check from two European regions (Falkenstein (Germany) and Helsinki (Finland)), and attaches DNS, certificate, redirect, and deploy-marker diffs right next to each confirmed incident. When a client site returns 502, 504, 522, an SSL failure, or NXDOMAIN, you receive the phase timings, likely cause, evidence, and client-ready draft summary in one view. Run an instant check with our website down checker or see how two-region checks work.

Questions

How can I tell quickly if a 502 or 522 error is only happening on my network or for all visitors?

Run the URL in our free website down checker, which executes a live external DNS, TCP, TLS, and HTTP check from outside your network and reports phase-by-phase timings without storing the address.

Why does a website show a 504 timeout when the server looks up in the hosting panel?

Because the operating system and web proxy are still running while upstream PHP-FPM, Node.js, or database workers are blocked waiting on locks or slow downstream calls beyond the gateway timeout.

Can an inside-WordPress plugin alert me during a 502, 522, or NXDOMAIN outage?

No. When DNS fails, TLS handshakes break, or PHP-FPM crashes with a 502, code inside WordPress cannot execute to send an alert. External multi-region monitoring verifies what real browsers actually receive.

What causes a sudden SERVFAIL right after changing nameservers?

Leaving a stale DNSSEC DS record active at the domain registrar after switching DNS providers causes validating resolvers to reject the entire zone until DNSSEC is disabled or updated with the new provider’s keys.

Sources

Read on . Standards and vendor pages change; confirm the current text before you rely on it.

Terms used in this guide

  • HTTP status codeAn HTTP status code is the three-digit number that opens a server’s response: 2xx success, 3xx redirect, 4xx client error, 5xx server error.
  • TLS certificateA TLS certificate proves a website holds the name in the address bar and enables HTTPS. What it contains, how long it lasts, what expiry breaks.
  • DNS recordA DNS record is one entry in a domain’s zone that maps a name to an address, a mail server or a text value. The common types and what breaks.
  • NameserverA nameserver is the server that holds a domain’s DNS records and answers queries for them. Why moving nameservers moves the whole zone and what to copy first.
  • IncidentAn incident is a period in which a monitored site is confirmed to be failing, from first confirmation to recovery. What an incident record should hold.

Try it on your own sites.

Add your sites: checking starts as soon as you do.

No card for the Free plan.