↑ ↓ select, Enter open, Esc close

Find the cause of a 502 Bad Gateway in the nginx log

Adjust the values, the command updates live
root@server
grep -E "upstream|connect\(\) failed" /var/log/nginx/error.log | tail -20

Shows the last 20 messages where nginx could not reach the backend (PHP-FPM, Apache or a Node application) or did not get a valid response. Typical messages are connect() failed (111: Connection refused) when the backend is stopped, or upstream prematurely closed connection when PHP processes crashed. The upstream: part of the message reveals which target is meant.

Note: On Plesk, use /var/www/vhosts/system/<domain>/logs/proxy_error_log as the log.

Also searched as

  • nginx 502 bad gateway cause
  • nginx upstream error log
  • connect() failed upstream
  • php-fpm not responding nginx

Related one-liners

All in nginx

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.