A 404 on a file that is clearly on disk is, in my book, nearly always a root that should have been an alias, or the other way round. The two directives look alike and build the file path in a different way.
root glues the whole request URI onto the folder. alias swaps the part that matched the location for the folder. Both of these serve /data/w3/images/top.gif for a request to /i/top.gif:
location /i/ {
alias /data/w3/images/;
}
location /images/ {
root /data/w3;
}
The second one gets the request /images/top.gif. Write root /data/w3/images; there and nginx goes looking for /data/w3/images/images/top.gif, which is the classic doubled folder. So the rule I keep in my head: when the last part of the folder is the same as the location, use root and leave that part off. That is what the nginx docs recommend as well. When the URL and the folder have different names, like /i/ and images, you need alias.
An example for a self-hosted app: serve the static files of an app from /mnt/user/appdata/<app>/static under /assets/ with alias /mnt/user/appdata/<app>/static/; inside location /assets/.
The caveat is the trailing slash. alias is a plain text swap, so the slashes on both sides have to agree. With location /i/ and alias /data/w3/images; (no slash) the request /i/top.gif becomes /data/w3/imagestop.gif. The opposite mistake, location /i without a slash and an alias with one, is worse: a request for /i../secret.txt then turns into /data/w3/images/../secret.txt, one folder above the one you meant. Keep both with a slash or both without, and run nginx -t after the change.
Further reading: ngx_http_core_module: alias, ngx_http_core_module: root
Going deeper: 🛜 Guide: AdGuard Home + Tailscale (Secure Split-Horizon DNS)