Back to Blog

Common Website Errors: 403, 404, 500 & 502 Explained

Common Website Errors: 403, 404, 500 & 502 Explained
Command of the Day
tail -n 20 /var/log/nginx/error.log

What it does: Prints the 20 most recent entries from the Nginx error log to quickly diagnose the root cause of HTTP 4xx and 5xx errors.

When browsing or maintaining a website, HTTP response status codes inform client browsers whether a web request succeeded or failed. While 200 OK means smooth operation, encountering 4xx client errors and 5xx server errors can be frustrating if you don't know where to look.

In this guide, we break down the four most common website errors (403, 404, 500, and 502) and provide immediate command-line fixes for your RivinCloud VPS.


1. HTTP 403: Forbidden

What It Means:

The web server understood the request, but refuses to authorize access. The resource exists, but permission is denied.

Common Causes:

  1. Incorrect Linux file permissions: The web server process (www-data or nginx) does not have read permissions on the directory or file.
  2. Missing Directory Index: Nginx is configured to serve a directory with autoindex off, but no index.html or index.php file exists inside that folder.
  3. IP blocking / .htaccess restriction: A firewall, security plugin, or .htaccess rule is explicitly denying access to your IP address.

How to Fix:

# Correct ownership to web server user
sudo chown -R www-data:www-data /var/www/html/

# Set standard directories to 755 and files to 644
sudo find /var/www/html -type d -exec chmod 755 {} \;
sudo find /var/www/html -type f -exec chmod 644 {} \;

2. HTTP 404: Not Found

What It Means:

The web server is reachable and running, but it cannot locate the requested file or URI path on the filesystem.

Common Causes:

  1. Typo in URL or wrong root path: The root directive in your Nginx/Apache configuration points to a non-existent or misnamed directory.
  2. Missing URL Rewrite Rules: For Single-Page Apps (React/Vue) or WordPress permalinks, Nginx needs a fallback rewrite rule to send requests to index.html or index.php.

How to Fix in Nginx:

Ensure your location / block includes try_files:

location / {
    try_files $uri $uri/ /index.php?$args;
}

3. HTTP 500: Internal Server Error

What It Means:

The web server encountered an unexpected condition or runtime crash that prevented it from fulfilling the request.

Common Causes:

  1. PHP Syntax / Fatal Error: A syntax error, missing PHP extension, or unhandled exception crashed the script.
  2. Malformed .htaccess (Apache): A typo or unsupported directive in .htaccess.
  3. Database Connection Failure: The application failed to authenticate to MySQL with the configured database credentials.

How to Diagnose:

Check your web server and PHP error logs immediately:

# For Nginx:
sudo tail -n 25 /var/log/nginx/error.log

# For Apache:
sudo tail -n 25 /var/log/apache2/error.log

# For PHP-FPM:
sudo tail -n 25 /var/log/php8.2-fpm.log

4. HTTP 502: Bad Gateway

What It Means:

The web server (acting as a reverse proxy) attempted to forward the request to an upstream backend daemon (like PHP-FPM, Node.js, Python Gunicorn, or Docker), but received an invalid response or the backend was completely unreachable.

Common Causes:

  1. Backend Daemon Is Stopped: PHP-FPM or your Node.js application crashed or is not running.
  2. Socket Path Mismatch: Nginx is configured to look for /run/php/php8.1-fpm.sock when the server actually has php8.2-fpm running.
  3. Port Conflict / Timeout: The backend service timed out or hung during execution.

How to Fix:

# Check if PHP-FPM is running
sudo systemctl status php8.2-fpm
sudo systemctl restart php8.2-fpm

# Check if Node.js / Python PM2 app is running
pm2 status

Common Mistakes

  • Guessing instead of reading log files: Server logs tell you the exact line number, file name, and error message causing the issue.
  • Granting 777 permissions: Never use chmod -R 777 to fix 403 errors; this creates severe security vulnerabilities.

Summary Troubleshooting Checklist

Error Code First Command to Run
403 Forbidden sudo chmod -R 755 /var/www/html
404 Not Found Verify root directive in /etc/nginx/sites-available/
500 Internal sudo tail -n 50 /var/log/nginx/error.log
502 Bad Gateway sudo systemctl status php*-fpm

Conclusion

Understanding HTTP status codes turns mysterious website crashes into quick, solvable fixes. Keep your RivinCloud VPS logs monitored to maintain 99.9% uptime!