Blog · WebJi® India

How to Fix a 502 Bad Gateway Error

Quick answer: How to Fix a 502 Bad Gateway Error from WebJi®, billed in INR with 18% GST on the invoice. Email support@webji.services is 24/7 in Hindi and English (average first reply under 60 minutes). Phone +91 141 4941811 is business hours only. The company has been in this business since 2005.
✓ In business since 2005✓ INR + GST billing✓ 24/7 Email Support — avg reply < 60 min
Indian trader monitoring candlestick charts on multiple screens in evening light — how to fix 502 bad gateway

What a 502 Bad Gateway Actually Means

What a 502 actually is: the gateway — Nginx proxying to an app server, Apache with a proxy, a load balancer — received an invalid or no response from the upstream it asked. Quick fixes in under five minutes, in order:

  1. Reload the site twice — rule out a blip.
  2. Check whether the app process is alive: restart PHP-FPM (systemctl restart php8.3-fpm) or the app service.
  3. Check resource state — free -m, df -h: a full disk or OOM kill presents as 502.
  4. Read the gateway error log (Nginx error.log) — it names the upstream failure verbatim: connection refused (process dead) versus timeout (process slow) versus permission denied (socket path).

If 502s appear only during traffic peaks, the pool is out of workers — see the PHP-FPM tuning section. Persistent 502 behind Cloudflare means the origin is sick; cure the origin and the CDN error clears with it.

Quick Fixes in Under 5 Minutes

Two practical notes on 502 Bad Gateway: it interacts directly with caching and database response, and misconfiguration is the most common cause of 'hosting is slow' tickets. WebJi® support checks it as part of standard migrations.

Indian trader monitoring candlestick charts on multiple screens in evening light — how to fix 502 bad gateway

PHP-FPM Tuning: pm.max_children and Workers

PHP-FPM tuning, the load-hour 502s: when 502s appear only during traffic peaks, the pool is out of workers. Each concurrent request occupies a child until it finishes; when all children are busy, new requests queue and then fail, surfacing as 502 or 503 at the proxy.

The settings live in the pool file — /etc/php/8.3/fpm/pool.d/www.conf: pm (dynamic, static or ondemand), pm.max_children (the ceiling that matters), pm.start_servers, pm.min_spare_servers, pm.max_spare_servers. The max_children formula: RAM available to FPM divided by average process memory. Measure the latter with ps --no-headers -o rss -C php-fpm8.3 during normal load; a typical WordPress process runs 50–100 MB. On a 2 GB server with ~600 MB usable and 75 MB average: pm.max_children = 8 — deliberately modest; oversubscribing causes OOM kills, which look like mysterious rolling 502s. After editing: systemctl restart php8.3-fpm.

Nginx Timeout and Buffer Settings

For “Nginx Timeout and Buffer Settings”, change one thing at a time and reload in a private window. Note the exact error text, the URL, and what you changed last — that is what support needs. If the site was fine before an update or a DNS edit, undo that edit first. Email support@webji.services (24/7, Hindi and English) or open a ticket at https://billing.webji.in/submitticket.php?step=2&deptid=10. A 2 a.m. fault goes to email, not to the phone line.

502 Behind Cloudflare or a CDN

502 behind Cloudflare or a CDN — reading the variant: a Cloudflare-branded 502 reports that Cloudflare could not get a valid response from your origin. Test the origin directly: curl -I --resolve yourdomain.com:443:ORIGIN_IP https://yourdomain.com.

The 52x variants carry distinct meanings: 522 — connection timed out, origin firewall dropping Cloudflare IPs or origin down; whitelist the CDN ranges. 521 — origin actively refused; the web server crashed, restart it. 525 — SSL handshake failure between CDN and origin; fix the origin certificate or set SSL mode to Full (strict) with a valid cert.

The pattern to internalise. With a CDN in front, a 502 is a report about your origin's health — diagnose the origin directly (the 504 sibling error follows the same logic), cure it, and the CDN's error clears with it.

Prevention: Monitoring and Resource Headroom

Two practical notes on proxy timeouts: it interacts directly with caching and database response, and misconfiguration is the most common cause of 'hosting is slow' tickets. WebJi® support checks it as part of standard migrations.

Frequently Asked Questions

How do I fix a 502 Bad Gateway error?

Read the gateway error log (Nginx error.log) — it names the upstream failure verbatim: connection refused (process dead) versus timeout (process slow) versus permission denied (socket path).

What causes 502 errors on my website?

What causes 502 errors on my website refers to the subject of this page, How to Fix a 502 Bad Gateway Error. WebJi® has provided this class of service from Jaipur since 2005, with GST invoices and 24/7 email at support@webji.services. Use the sections and the table on this page for the specifics, and open a ticket at https://billing.webji.in/submitticket.php?step=2&deptid=10 if your case does not match the standard row.

Is a 502 error my fault or my host's?

For “Is a 502 error my fault or my host's”: For “Nginx Timeout and Buffer Settings”, change one thing at a time and reload in a private window. Note the exact error text, the URL, and what you changed last — that is what support needs. If the site was fine before an update or a DNS edit, undo that edit first.

How do I restart PHP-FPM?

Check whether the app process is alive: restart PHP-FPM (systemctl restart php8.3-fpm) or the app service.

Why does 502 appear only during high traffic?

If 502s appear only during traffic peaks, the pool is out of workers — see the PHP-FPM tuning section. Persistent 502 behind Cloudflare means the origin is sick; cure the origin and the CDN error clears with it.

What does a 502 from Cloudflare mean?

What does a 502 from Cloudflare mean refers to the subject of this page, How to Fix a 502 Bad Gateway Error. WebJi® has provided this class of service from Jaipur since 2005, with GST invoices and 24/7 email at support@webji.services. Use the sections and the table on this page for the specifics, and open a ticket at https://billing.webji.in/submitticket.php?step=2&deptid=10 if your case does not match the standard row.

Is WebJi® an Indian company?

Yes. WebJi® is headquartered in Jaipur, Rajasthan and has operated since 2005. Billing, support and governance all run from India.

Do you provide GST invoices?

Every purchase and renewal gets a GST invoice with our GSTIN, and hosting prices are quoted exclusive of 18% GST. Claim input credit as applicable.

Need help with this?

WebJi® support does it for you — free. Talk to our Jaipur team →