Web Development & Performance
How to Troubleshoot and Fix Common HTTP Error Codes
Last reviewed
Summary: 4xx codes mean the request was refused or not found; 5xx codes mean the server failed. Always start with the server's error log: it names the exact file, permission or upstream that failed. 403 is usually permissions, 500 an application error, 502 a crashed or unreachable backend, and 504 a backend that is too slow.
01
2xx
Success
02
3xx
Redirect — check for loops
03
4xx
Client/request problem
04
5xx
Server/application problem
Where to find the logs
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/apache2/error.log
sudo journalctl -u php8.3-fpm --since "10 min ago"403 Forbidden
- File permissions: directories usually 755, files 644, owned by the web user.
- No index file and directory listing disabled.
- A deny rule in Nginx config or .htaccess, or a security plugin/WAF blocking your IP.
sudo find /var/www/example.ca -type d -exec chmod 755 {} \;
sudo find /var/www/example.ca -type f -exec chmod 644 {} \;404 Not Found
The URL does not match a file or route. Check try_files in Nginx, rewrite rules in .htaccess, and CMS permalink settings. For moved content, add a 301 redirect rather than leaving a 404 — and design a helpful custom 404 page.
500 Internal Server Error
- PHP fatal error: look for 'PHP Fatal error' in the error log.
- Syntax error in .htaccess on Apache.
- Exhausted memory_limit or a failing plugin after an update.
502 Bad Gateway
Nginx could not get a valid response from the upstream (PHP-FPM, Node.js, a proxy). Typical log line: 'connect() to unix:/run/php/php8.3-fpm.sock failed'. Confirm the service is running and the socket path matches.
systemctl status php8.3-fpm
ls -l /run/php/504 Gateway Timeout
The upstream accepted the request but took too long. Find the slow request (slow query log, PHP-FPM slowlog), fix the cause, and only then consider raising fastcgi_read_timeout. If all PHP-FPM workers are busy, revisit pm.max_children in our LEMP guide.
| Code | Likely cause | First check |
|---|---|---|
| 403 | Permissions or deny rule | Error log; ls -l |
| 404 | Missing file or route | try_files / rewrites |
| 500 | Application crash | PHP error log |
| 502 | Backend down or wrong socket | systemctl status |
| 503 | Overloaded or maintenance | Load, maintenance flag |
| 504 | Backend too slow | Slow logs, worker count |
More on performance in web development and server setup in server infrastructure.
Get new technical guides by email
Occasional, practical server and hosting tutorials for Canadian webmasters. Unsubscribe any time.