502 Bad Gateway usually means your backend app (PHP-FPM, Node.js, Gunicorn) is stopped or crashed.
sudo systemctl status php8.2-fpm
sudo tail -n 50 /var/log/nginx/error.log504 Gateway Timeout means the backend took too long to reply. Increase proxy_read_timeout 120s; or fastcgi_read_timeout 120s; in Nginx and optimize slow database queries.