Эта страница пока не переведена.

HTTP 502 Bad Gateway

A gateway or proxy got an invalid response from the upstream server.

Обновлено

502
Bad Gateway
5xx Server error
Class
RFC 9110 §15.6.3
Defined in

What does HTTP 502 mean?

A gateway or proxy got an invalid response from the upstream server. You see 502 from Nginx, Cloudflare, load balancers and CDNs when the application server behind them crashed, refused the connection or returned something that is not valid HTTP.

5xx Server error: The request looked valid, but the server failed to fulfil it. The fix is on the server side.

Common causes of a 502 error

  • The application process crashed or is not running (PHP-FPM, Node, Gunicorn).
  • Wrong upstream port or socket in the proxy config.
  • Firewall blocking the proxy from the origin.
  • Origin response headers too large for the proxy buffers.

How to fix 502 Bad Gateway

  • Check that the app server is running and listening on the configured port.
  • Read the proxy’s error log (for Nginx: connect() failed or upstream prematurely closed).
  • Restart the application and check its own logs.

How to find the cause of a 502

A 502 means the proxy reached your app but got a bad answer, or nothing, so check the app first.

sudo systemctl status your-app
sudo tail -n 30 /var/log/nginx/error.log
curl -I http://127.0.0.1:3000/

If connect() failed (111: Connection refused) appears in the log, the app is down or listening on another port. If the local curl works, the proxy’s upstream setting is wrong. Behind Cloudflare, the error page shows whether your server or Cloudflare is failing.

502 and SEO

Like 500 — short incidents are fine, ongoing 502s reduce crawling and indexing.

Example response

HTTP/1.1 502 Bad Gateway

How to return a 502 response

Node.js (Express)

res.status(502).json({ error: 'Bad Gateway' });

PHP

http_response_code(502);

Python (Flask)

return {'error': 'Bad Gateway'}, 502

Go (net/http)

w.WriteHeader(502)

nginx

return 502;

Related status codes

Check which status code a URL returns with the HTTP header checker.

All HTTP status codesSearch the full list of status codes from 100 to 599 with their meanings and SEO impact.
Open the full list

Часто задаваемые вопросы

What does status code 502 mean?
502 Bad Gateway: A gateway or proxy got an invalid response from the upstream server.
How do I fix a 502 error?
Check that the app server is running and listening on the configured port. Read the proxy’s error log (for Nginx: connect() failed or upstream prematurely closed).
Does 502 affect SEO?
Like 500 — short incidents are fine, ongoing 502s reduce crawling and indexing.