502 Bad Gateway
Gateway/proxy received invalid response from upstream server.
The server received an invalid response from the upstream server.
What HTTP 502 Bad Gateway Means
The server received an invalid response from the upstream server.
Gateway/proxy received invalid response from upstream server.
Common Causes
- Upstream server down
- PHP-FPM not running
- Application server crashed
- Network issue between servers
- Firewall blocking connection
How to Fix It (For Visitors)
- Refresh the page
- Try again in a few minutes
- Contact website administrator
How to Fix It (For Developers/Admins)
- Check upstream server status
- Restart PHP-FPM/application server
- Check Nginx proxy_pass configuration
- Verify firewall rules
- Check application server logs
- Increase timeout settings
Returning a 502 Bad Gateway (Code Examples)
If you build APIs or web apps, here is how to send an HTTP 502 response and how to test for it:
Node.js (Express)
app.get('/resource', (req, res) => {
res.status(502).json({ error: 'Bad Gateway' });
});
Python (Flask)
@app.route('/resource')
def resource():
return jsonify(error='Bad Gateway'), 502
PHP
<?php
http_response_code(502);
header('Content-Type: application/json');
echo json_encode(['error' => 'Bad Gateway']);
Check the status with curl
curl -I https://example.com/resource
# Look for: HTTP/1.1 502 Bad Gateway
Frequently Asked Questions
What does HTTP 502 Bad Gateway mean?
Gateway/proxy received invalid response from upstream server. In short: The server received an invalid response from the upstream server.
Is a 502 Bad Gateway error my fault or the website's?
502 is a 5xx server-error code, so the problem is on the server side, not your browser or device. As a visitor you can usually only retry; if you run the site, investigate the server.
How do I fix a 502 Bad Gateway error?
Check upstream server status. Restart PHP-FPM/application server. Check Nginx proxy_pass configuration.
Official Specification
The 502 Bad Gateway status code is defined in RFC 7231 Section 6.6.3.