Fixing 502 Bad Gateway and 503 Service Unavailable Errors
Learn what 502 Bad Gateway and 503 Service Unavailable mean, why they happen, and how to troubleshoot CDN, origin, hosting and server issues.
Introduction
502 Bad Gateway and 503 Service Unavailable are server-side errors. They usually mean the browser reached something — such as a web server, proxy, CDN or load balancer — but the website application, origin server or upstream service could not respond correctly.
A 502 often points to a broken connection between a gateway/proxy and the origin. A 503 usually means the server or application is temporarily unavailable because of overload, maintenance, rate limiting, resource limits or service failure.
Quick answer
A 502 Bad Gateway means a proxy, CDN or gateway received an invalid response from the upstream server. A 503 Service Unavailable means the server is temporarily unable to handle the request. Check the CDN/proxy, origin server, web server, PHP/app service, database, firewall, maintenance mode and resource limits.
502 and 503 errors
Both 502 and 503 are 5xx server-side errors, but they point to different failure patterns.
502 Bad Gateway
A gateway, proxy, CDN or load balancer contacted an upstream server but received an invalid, broken or unexpected response.
503 Service Unavailable
The server or application is temporarily unavailable, overloaded, in maintenance, rate-limited or unable to process the request.
The browser may show the same error to users, but the fix depends on where the request fails.
502 vs 503
502 Bad Gateway
- Usually means: The gateway or proxy cannot get a valid response from upstream.
- Common layer: CDN, reverse proxy, load balancer, Nginx/Apache proxy, upstream app.
- Typical causes: Origin down, PHP-FPM crash, upstream timeout, firewall block, proxy misconfiguration, invalid upstream response.
503 Service Unavailable
- Usually means: The server is reachable but temporarily cannot serve the request.
- Common layer: Web server, app server, hosting limits, maintenance mode, rate limiting.
- Typical causes: Overload, maintenance mode, resource limits, app unavailable, worker exhaustion, WAF/rate limits.
502 causes
Origin server down
The CDN or proxy cannot reach the hosting server.
PHP-FPM or app service stopped
Nginx/Apache receives no valid response from the application backend.
Upstream timeout
The application takes too long to respond.
Firewall blocks proxy/CDN
The origin blocks requests from CDN or load balancer IPs.
Wrong upstream address
Proxy configuration points to the wrong port, socket or server.
Bad SSL between CDN and origin
The CDN cannot establish a valid HTTPS connection to the origin.
Application crash
The app returns broken or incomplete responses.
DNS to origin changed
CDN or proxy still points to an old or wrong origin.
503 causes
Server overload
CPU, RAM, disk I/O or database load is too high.
Hosting resource limits
Shared hosting or CloudLinux limits are reached.
Maintenance mode
CMS, plugin, deployment or provider maintenance is active.
Too many workers busy
PHP-FPM, Node, Python or web server workers are exhausted.
Rate limiting
WAF, CDN or application rate limits block traffic temporarily.
Database unavailable
The app cannot connect to its database.
Plugin/theme failure
A WordPress plugin or theme causes the site to fail.
DDoS or traffic spike
Large traffic overwhelms the website stack.
Error source
Before fixing, identify which layer generated the error.
- browser/client
- CDN edge
- WAF/security layer
- load balancer
- reverse proxy
- web server
- application server
- PHP-FPM/app runtime
- database
- origin hosting server
Error pages often reveal the layer. For example, a CDN-branded 502 may indicate CDN-to-origin failure, while a hosting-branded 503 may indicate resource limits or maintenance.
Why this matters
502 and 503 errors matter because users, search engines and monitoring tools cannot reliably access the site. Short incidents may be temporary, but repeated 5xx errors can hurt conversions, trust, uptime monitoring and search engine crawling.
These errors should be investigated from the outside in: public URL, CDN/proxy, origin server, application service, database and logs.
How to diagnose
Use Website Status Checker to confirm the exact status code, final URL and whether the error is consistent.
Check in this order:
- Exact URL — Test the affected page, not only the homepage.
- Error code — Confirm whether it is 502, 503, 504 or another status.
- Error source — Check whether the page is from CDN, proxy, hosting server or application.
- CDN/proxy status — Bypass CDN if possible or check origin directly.
- Origin server — Confirm the hosting server is online and listening on HTTP/HTTPS.
- Web server logs — Review Nginx/Apache errors.
- App runtime — Check PHP-FPM, Node, Python, Ruby or other backend services.
- Database — Confirm database connectivity and load.
- Resource usage — Check CPU, RAM, disk, processes, workers and limits.
Confirm the error
Use Website Status Checker to confirm the exact status code, final URL and whether the error is consistent.
Common problems
CDN cannot reach origin
HighThe CDN edge responds with 502 because the origin server is unreachable or blocked.
Next step: Check origin IP, firewall rules, CDN origin settings and SSL mode.
PHP-FPM is down
HighThe web server cannot get a valid response from PHP.
Next step: Restart PHP-FPM, review error logs and check worker/process limits.
Application timeout
HighThe upstream app takes too long to respond.
Next step: Check slow database queries, plugins, external API calls and timeout settings.
Server overloaded
HighCPU, RAM, disk I/O or workers are exhausted.
Next step: Check resource usage, traffic spikes and hosting limits.
Maintenance mode active
MediumCMS or deployment maintenance mode returns 503.
Next step: Disable maintenance mode after confirming deployment finished correctly.
Database unavailable
HighThe application cannot connect to the database.
Next step: Check database service, credentials, socket/host and server load.
Firewall or WAF blocking traffic
MediumSecurity rules may block CDN, proxies, bots or real visitors.
Next step: Review WAF/firewall logs and allow legitimate CDN/proxy IPs.
Wrong proxy upstream
HighNginx, Apache or load balancer points to the wrong backend.
Next step: Check upstream host, port, socket and service status.
Shared hosting limits reached
MediumThe account hits CPU, memory, entry process or I/O limits.
Next step: Review hosting resource usage and optimize or upgrade if needed.
How to fix errors
-
Step 1: Confirm the public error
Use Website Status Checker and record the exact status, URL and response source.
-
Step 2: Check CDN/proxy layer
Review CDN origin settings, SSL mode, cache and WAF/firewall rules.
-
Step 3: Check origin availability
Confirm the hosting server responds directly on HTTP/HTTPS.
-
Step 4: Check web server logs
Review Nginx/Apache error logs for upstream, proxy, timeout or permission errors.
-
Step 5: Check application runtime
Restart and inspect PHP-FPM, Node, Python, Ruby or other backend services.
-
Step 6: Check database
Confirm database service is running and not overloaded.
-
Step 7: Check resources and limits
Review CPU, RAM, disk, I/O, workers, entry processes and account limits.
-
Step 8: Disable bad plugin/deployment if needed
If the error started after an update, rollback or disable the recent change.
-
Step 9: Monitor after recovery
Watch logs, response time and resource usage to confirm the error does not return.
Example 1: 502 from CDN
Public check:
https://example.com → 502 Bad Gateway
Origin check:
https://origin.example.com → timeout
Likely cause:
CDN cannot reach origin server.
Fix:
Check origin server status, firewall, CDN origin IP and SSL mode.
Example 2: 503 on shared hosting
Public check:
https://example.com → 503 Service Unavailable
Hosting panel:
Entry processes limit reached.
CPU usage high.
Likely cause:
Account resource limits.
Fix:
Reduce plugin load, cache pages, review bots, optimize PHP/database or upgrade plan.
Example 3: Nginx 502
Nginx error:
connect() to unix:/run/php/php8.2-fpm.sock failed
Likely cause:
PHP-FPM stopped or socket path wrong.
Fix:
Restart PHP-FPM and verify Nginx fastcgi_pass configuration.
Examples are illustrative. Review your real logs and hosting stack before applying commands or config changes.
Check public status:
curl -I https://example.com
Follow redirects:
curl -IL https://example.com
Check web server status:
systemctl status nginx
systemctl status apache2
Check PHP-FPM:
systemctl status php-fpm
systemctl status php8.2-fpm
Check recent Nginx errors:
tail -100 /var/log/nginx/error.log
Check recent Apache errors:
tail -100 /var/log/apache2/error.log
Check disk:
df -h
Check memory:
free -m
Check load:
uptime
Check processes:
top
Commands are illustrative and vary by operating system, control panel and server stack. Do not restart services on production servers without understanding the impact.
WordPress checks
For WordPress sites, 502 and 503 errors often happen after plugin updates, theme changes, heavy traffic or PHP resource exhaustion.
- recently updated plugins
- active theme errors
- PHP fatal errors
- maintenance mode file
- wp-config.php changes
- database connection
- object/cache plugin
- security plugin/WAF rules
- PHP memory limit
- PHP-FPM worker limits
- long-running admin-ajax requests
- WooCommerce or cron load
If WordPress fails after an update, temporarily disable the latest plugin/theme and review error logs before making more changes.
Hosting checks
On shared hosting, 503 errors may appear when resource limits are reached.
- CPU usage
- physical memory
- virtual memory
- entry processes
- I/O usage
- IOPS
- number of processes
- PHP errors
- Apache/Nginx logs
- ModSecurity blocks
- account suspension or limits
If one account repeatedly hits limits, optimization or a higher hosting plan may be needed.
Server checks
On VPS or dedicated servers, check the full service stack.
- web server running
- PHP-FPM/app service running
- database running
- disk space
- RAM/swap usage
- CPU load
- firewall rules
- fail2ban/WAF blocks
- system logs
- upstream socket/port
- SSL certificate on origin
- proxy configuration
A 502 from Nginx often means the upstream service, socket or port is not responding correctly.
Frequently asked questions
What does 502 Bad Gateway mean?
A proxy, CDN or gateway could not get a valid response from the upstream server.
What does 503 Service Unavailable mean?
The server or application is temporarily unable to handle the request.
Is 502 a DNS problem?
Usually no. DNS may point to the wrong origin, but 502 normally means a gateway/upstream response problem.
Can a CDN cause 502 errors?
Yes. A CDN can return 502 if it cannot reach the origin or receives an invalid response.
Can WordPress cause 503 errors?
Yes. Plugin errors, maintenance mode, database issues or resource limits can trigger 503.
What should I check first?
Check whether the error comes from CDN/proxy, origin server, application runtime or hosting limits.
Are repeated 502/503 errors bad for SEO?
Yes, persistent 5xx errors can affect crawling and user experience.
Related tools
Use these free tools to verify your configuration after applying changes.
Related guides
Browse all Website Health guides →Need help applying this fix?
Send us your domain, report link or issue details. CheckDomainHealth will review the request and route it to the right technical team if hands-on support is needed.
Was this guide helpful?
Your feedback helps us improve our guides for everyone.
Thanks for your feedback!