Website showing 502 bad gateway error during peak hours
Summary
This guide helps you troubleshoot and resolve: Website showing 502 bad gateway error during peak hours. Follow the steps below to fix the issue.
Common Causes
A 502 Bad Gateway error indicates that your web server, acting as a gateway or proxy, received an invalid response from an upstream server. During peak traffic hours, this usually points to server resource limits, upstream service timeouts, or proxy misconfigurations. For small business websites, these errors often occur when the hosting environment cannot handle concurrent visitor requests, causing the gateway to fail while waiting for a response from the backend application or database server.
Quick Fix Steps
- Refresh your website after waiting one to two minutes to see if the error clears.
- Clear your browser cache or test the site in an incognito window to rule out cached error pages.
- Check your hosting provider's status page for any reported outages or maintenance.
- If you manage your own server, restart the web server and application services.
Detailed Instructions
Check Server Resource Usage
- Log in to your hosting control panel or connect to your server via SSH.
- Open the system resource monitor to view current CPU and memory usage.
- On Linux servers, run
toporhtopto identify processes consuming excessive resources. - Look for memory spikes or CPU usage consistently near 100% during peak traffic periods.
- If resource limits are being reached, consider upgrading your hosting plan or optimising your website code and database queries.
Review Server Logs
- Locate your web server error logs. Common file paths include
/var/log/nginx/error.logor/var/log/apache2/error.log. - Open the log file using a text editor or run
tail -f /var/log/nginx/error.logto monitor entries in real time. - Search for entries matching the time when the 502 error occurred.
- Look for messages indicating upstream timeouts, connection refusals, or PHP-FPM errors.
- Note any recurring patterns that correlate with high traffic periods.
Verify Upstream Service Configuration
- Confirm that your backend application service is running. For example, check PHP-FPM, Node.js, or your application server status.
- Review your proxy configuration file, typically located in
/etc/nginx/sites-available/or/etc/apache2/sites-available/. - Ensure the proxy pass directive points to the correct upstream address and port.
- Check that timeout values are sufficient for your application's processing needs during peak load.
- Reload the web server configuration after making changes using
sudo systemctl reload nginxorsudo systemctl reload apache2.
If you are unsure about editing server configuration files, create a backup before making changes. Incorrect syntax in files like nginx.conf or .htaccess can take your website offline completely.
Avoid making changes to live production server settings during business hours unless you have tested them in a staging environment first.
If you have checked your server resources, reviewed logs, and verified your proxy configuration but the 502 Bad Gateway error continues during peak hours, your hosting environment may be outgrown for your current traffic levels. Contact your hosting provider to discuss upgrading your plan or migrating to a more robust infrastructure.
If you host with us, you don't need to do this yourself — just Open a Ticket and our team will get it sorted.
Still Having Issues?
💻 Open a Ticket