What such an error means
Good news first: if the browser shows error 500, 502, 503 or 504, the server is running. It got the request and answered, it just sent back an error instead of the page. If the server were off, the browser wouldn't get any answer at all. So the cause is somewhere inside: in the web server, PHP, the database or the site itself.
The error code tells you where to look first:
- 500 — something broke in the site itself. It may be the code, a plugin, the
.htaccessfile or the PHP settings; - 502 — nginx passed the request on to PHP or the application and got no answer. Most often they've simply stopped;
- 503 — the site isn't taking requests right now. It's overloaded, or maintenance mode is on;
- 504 — the answer took too long, and the web server stopped waiting. Heavy database queries are the usual reason.
Look at the error log
The cause is almost always written in the error log. Connect over SSH and look at the last lines:
tail -n 50 /var/log/nginx/error.log
For Apache the path is /var/log/apache2/error.log (Debian, Ubuntu) or /var/log/httpd/error_log (AlmaLinux, Rocky). If your sites are set up through a control panel, each domain usually has a log of its own. In Hestia you'll find it in /var/log/apache2/domains/ or /var/log/nginx/domains/.
The database isn't running
Very often MySQL or MariaDB has stopped. WordPress then says "Error establishing a database connection", and other sites just return 500. Check whether the service is running:
systemctl status mariadb
If you have MySQL, the service is called mysql. If it's stopped, start it:
systemctl start mariadb
A database rarely falls over on its own. Usually the system stops it because the server ran out of memory. You can see it with this command:
dmesg -T | grep -i "killed process"
Found mysqld or mariadbd in the output? Then there isn't enough memory, and the database will keep falling over. What to do about it is covered in The server is slow or the CPU is at 100%.
PHP has stopped (error 502)
When nginx returns 502, check PHP-FPM first. Find out what the service is called, then look at its state:
systemctl list-units | grep fpm
systemctl status php8.2-fpm
Your version may differ, so use the one the first command showed. Start a stopped service with systemctl restart. And if it won't start, journalctl -u php8.2-fpm -n 50 will show why.
The disk is full
On a full disk the database can't write anything and PHP can't save sessions, so the site starts returning errors. This command shows the free space:
df -h
It also happens that there seems to be space, but files still can't be created. That means the inodes ran out: millions of small cache, session or report files used them up. Check that too:
df -i
Does the IUse% column say 100%? Find the folder with the most files and clean it up. If it's the space itself that's short, delete old logs and backups or enlarge the disk: Reconfiguring a virtual server.
The error appeared after a settings change
- A redirect loop in
.htaccess. You'll see the lineexceeded the limit of 10 internal redirectsin the log. Put the file back the way it was. - nginx won't start after a config edit.
nginx -tshows which file and which line has the error. - Manual edits disappeared by themselves. This happens in Hestia and Vesta. These panels rebuild the domain configuration from time to time, for example when they renew an SSL certificate, and whatever you changed directly in the domain's files is lost. So it's better to make your changes through the panel's templates.
Error 520–526 with Cloudflare
If the site runs through Cloudflare, the 52x errors come from Cloudflare itself, not from your server:
- 521 — the server isn't accepting connections: the web server is stopped or the firewall closed the port;
- 522 and 524 — the server didn't answer in time;
- 525 and 526 — something is wrong with the SSL certificate on the server, for example it has expired.
An error in the site's code
Sometimes the log points to a specific file and line in the code of the site, a theme or a plugin. Then the error is in the site itself. Updated the CMS or a plugin recently? Roll the update back or turn the plugin off. If not, send those lines to the site's developer.
If you can't find the cause
Contact support. Tell us the server, the site's address and when the error appeared, and if you can, attach the last lines of the log.
