← Back to all fixes

Static files return 404 through nginx

The Issue

HTML loads but all linked CSS and JS return 404.

Root Cause

The `root` or `alias` path in the nginx config points to the wrong directory, or the location block for static files is missing.

How to Fix
  1. Check the `root` directive in your nginx server block — it must point to the directory containing static files
  2. If serving from `/public`: `root /var/www/myapp/public;`
  3. Add explicit location for static extensions if needed: `location ~* \.(css|js|png)$ { root /var/www/myapp/public; }`
  4. Verify file actually exists on disk at the expected path
  5. Check nginx access log to see exact path being requested: `sudo tail -f /var/log/nginx/access.log`