How to fix 502 bad gateway error on my website
Summary
This guide helps you troubleshoot and resolve: How to fix 502 bad gateway error on my website. Follow the steps below to fix the issue.
Common Causes
A 502 Bad Gateway error occurs when your web server acts as a gateway or proxy and receives an invalid response from an upstream server. For small business websites, this often points to server performance issues, resource bottlenecks, or temporary network connectivity problems between servers. This guide will help you diagnose whether the error is a momentary glitch or a sign that your current hosting environment is underpowered for your needs.
Quick Fix Steps
- Refresh your browser page after waiting one to two minutes.
- Clear your browser cache and cookies, then reload the website.
- Try accessing your website from a different device or network to rule out local connectivity issues.
Detailed Instructions
Check Server Resource Usage
If your website is hosted on a shared or underpowered plan, resource throttling can cause the upstream server to become unresponsive.
- Log in to your hosting control panel.
- For cPanel users, navigate to Metrics > Resource Usage.
- Review CPU, memory, and entry process limits.
- Look for spikes that coincide with the times you encountered the 502 error.
- If resources are consistently maxed out, your site may have outgrown its current hosting plan.
Review Server Logs
Server error logs provide specific details about why the gateway is receiving invalid responses.
- Access the logs section in your hosting control panel.
- For cPanel users, navigate to Metrics > Errors or open the
error.logfile for your domain via File Manager. - Search for entries marked
502orupstreamaround the time of the error. - Note any recurring timestamps or specific scripts causing the failure.
Inspect Proxy and Firewall Settings
Misconfigured proxy settings or overzealous firewall rules can block legitimate traffic between servers.
- Check your website's proxy configuration if you use a reverse proxy or CDN.
- Ensure your origin server IP is whitelisted in your firewall or security plugin.
- Temporarily disable any security plugins to test if they are blocking upstream requests.
- Re-enable security features one by one to identify the conflicting rule.
Third-Party CDN and Proxy Services
If you use a third-party service such as Cloudflare, the 502 error may be occurring between the CDN and your origin server rather than on your hosting account.
- Visit the status page for your CDN provider (for example, the Cloudflare Status page) to check for ongoing outages.
- If the service is operational, try temporarily pausing the CDN or switching to "DNS Only" mode in your provider's dashboard to see if the origin server is the source of the error.
- Verify that your origin server IP is correct in the CDN settings.
Guidance for Managed Hosting and Website Builders
If you use a managed hosting provider or a website builder platform, you may not have access to server logs or a traditional control panel.
- Check the provider's status page or system health dashboard for reported incidents.
- Review any built-in analytics or uptime monitoring tools provided by the platform.
- If you cannot access logs or server settings, proceed directly to contacting your provider's support team.
Troubleshooting
When the Error is Temporary
Occasional 502 errors often resolve themselves. They may be caused by brief server restarts, minor network routing issues, or momentary traffic spikes. If your website returns to normal quickly and the error does not recur, no further action is usually required.
When the Error Persists
A persistent 502 Bad Gateway error typically indicates a deeper problem. Common causes include:
- Ongoing server overloads on shared hosting environments.
- Resource caps being reached due to increased website traffic.
- Geographical latency affecting domestic traffic between Australian users and overseas servers.
- Frequent timeouts caused by slow database queries or unoptimised scripts.
- Hardware failure or misconfiguration at the hosting provider level.
If you have checked your resource usage, reviewed your logs, and verified your proxy settings without finding a cause, the issue likely resides with your hosting provider's infrastructure.
Contacting Your Hosting Provider
When escalating the issue to your hosting provider, include the following information to help them diagnose the problem quickly:
- The exact dates and timestamps when you encountered the 502 error.
- Relevant excerpts from your server error logs.
- The troubleshooting steps you have already taken.
- Whether the error affects the entire website or only specific pages.
Still Having Issues?
💻 Open a Ticket