Fix 500, 502, 503 and 504 errors on your website

All of these mean you reached the server but the site failed to answer, and none comes from the visitor's device. 500 is a code error, 502 a stopped backend, 503 overload or maintenance, 504 a slow answer.

Last updated:

Start with the error log

The error log usually names the cause exactly, so read it before guessing. On a server it is at these paths. On shared hosting use Errors in cPanel or Logs in Plesk.

console
$ sudo tail -n 50 /var/log/nginx/error.log
$ sudo tail -n 50 /var/log/apache2/error.log

500 Internal Server Error

Usually a code error, a broken plugin, a bad line in .htaccess or wrong file permissions. Did it start after a change? Undo that first. Try renaming .htaccess for a moment, and turn off WordPress plugins by renaming the plugins folder.

console
$ mv .htaccess .htaccess.off
$ mv wp-content/plugins wp-content/plugins.off

502 Bad Gateway

The front (Nginx, for example) works but the service behind it does not answer, such as PHP-FPM or a Node.js app. Make sure it is running and restart it. The PHP version in the name depends on your server.

console
$ sudo systemctl status php8.3-fpm
$ sudo systemctl restart php8.3-fpm

503 Service Unavailable

The server is overloaded or in maintenance mode. Check memory and CPU, and in WordPress delete the .maintenance file from the site folder if a stopped update left it behind.

console
$ free -m
$ uptime
$ rm .maintenance

504 Gateway Timeout

The backend took longer than the time limit, usually because of a slow database query or an overloaded server. Fix the slowness first, and raise the limit only when needed, such as fastcgi_read_timeout in Nginx.

Was this page helpful?