Skip to content

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.

Which side is at fault?
  1. 01

    2xx

    Success

  2. 02

    3xx

    Redirect — check for loops

  3. 03

    4xx

    Client/request problem

  4. 04

    5xx

    Server/application problem

Where to find the logs

terminalbash
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.
terminalbash
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.

terminalbash
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.

CodeLikely causeFirst check
403Permissions or deny ruleError log; ls -l
404Missing file or routetry_files / rewrites
500Application crashPHP error log
502Backend down or wrong socketsystemctl status
503Overloaded or maintenanceLoad, maintenance flag
504Backend too slowSlow 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.