Short answer: the nginx worker user cannot get through the path to the file
An nginx 403 with (13: Permission denied) in the error log means the kernel refused to let the nginx worker process open the file. A file you can cat as root may still be closed to the worker (www-data or nginx). The cause is usually one of four:
- A parent directory lacks execute (x) permission — typical for a site under a home directory
- Uploaded or deployed files have the wrong mode or owner — only new files get 403
- The SELinux context is wrong — permissions look fine, 403 only on RHEL-family hosts
- Not permissions at all: no index file — the log line is different
First check: one line of the error log
tail -n 20 /var/log/nginx/error.log
2026/10/11 09:12:44 [error] 1234#1234: *57 open() "/var/www/html/uploads/report.pdf" failed (13: Permission denied), client: 203.0.113.10, server: example.com, request: "GET /uploads/report.pdf HTTP/1.1", host: "www.example.com"
open() ... failed (13: Permission denied)→ file permissions, path or SELinux (causes 1–3)directory index of "/var/www/html/app/" is forbidden→ no index file (cause 4)access forbidden by rule→ adenyrule in the config, not a permission problem
Who the worker runs as, and where it gets stuck
ps -o user,pid,cmd -C nginx
namei -l /var/www/html/uploads/report.pdf
f: /var/www/html/uploads/report.pdf
drwxr-xr-x root root /
drwxr-xr-x root root var
drwxr-xr-x root root www
drwxr-xr-x root root html
drwx------ deploy deploy uploads
-rw------- deploy deploy report.pdf
The worker user comes from the user directive in nginx.conf (usually www-data on Debian and Ubuntu, nginx on the RHEL family). namei -l shows every step of the path; the worker needs x on every directory and r on the file. Here uploads and report.pdf block it. Reproduce it directly with sudo -u www-data head -c1 <file>.
Causes 1 and 2: give x on directories, r on files
chmod 755 /var/www/html/uploads
chmod 644 /var/www/html/uploads/report.pdf
# under a home directory, add only x on the parent (no listing)
chmod o+x /home/deploy
If only newly uploaded files get 403, the upload or deploy tool's umask (077) or a copy of the source modes is the cause. Pin the modes in the deploy step (for example rsync -a --chmod=D755,F644 ./dist/ /var/www/html/).
Cause 3: SELinux
If namei shows correct permissions but you still get 403 and getenforce says Enforcing, look at SELinux. A file moved with mv from a home directory keeps its original label (user_home_t).
ls -Z /var/www/html/uploads/report.pdf
unconfined_u:object_r:user_home_t:s0 /var/www/html/uploads/report.pdf
ausearch -m avc -ts recent # avc: denied { read } ... comm="nginx"
restorecon -Rv /var/www/html # default path: restores httpd_sys_content_t
# for a non-default path, register a rule, then restorecon
semanage fcontext -a -t httpd_sys_content_t "/srv/site(/.*)?"
restorecon -Rv /srv/site
chcon -t httpd_sys_content_t is a temporary fix that the next restorecon reverts. If proxying fails with connect() ... failed (13: Permission denied) while connecting to upstream, you need setsebool -P httpd_can_network_connect 1.
Cause 4: no index file
If a directory URL has no index.html and autoindex is off (the default), you get 403 regardless of permissions. Check that root points at the build output and that the index file was actually deployed.
What not to do
chmod -R 777— anyone can now write to the web root. Grant only the x and r that are needed.- Leaving
setenforce 0in place as the fix — use it only to confirm the cause, then fix the labels.
The order to work in
- Read the line in
error.log:open() ... (13)ordirectory index ... forbidden - Check the worker user's x and r along the whole path with
namei -l→chmod - Permissions fine but still 403 →
getenforceandls -Z→restorecon - Pin modes and labels in the deploy script so it does not come back
To practise the same situation as a problem, start with the one-minute quiz nginx 403 with (13: Permission denied): only the newly uploaded file.
Quick diagnostic checklist
- In
/var/log/nginx/error.log, check for(13: Permission denied)versusdirectory index ... is forbidden. - Find the worker user (
www-dataornginx) withps -o user,pid,cmd -C nginx. - Run
namei -l <file path>and confirm every parent directory grants x. - Confirm the file itself grants the worker r.
- If only newly uploaded files fail, suspect the upload or deploy tool's umask or copied modes.
- If permissions are fine but 403 remains, check SELinux with
getenforceandls -Z. - Fix labels with
restorecon(aftersemanage fcontextfor a non-default path). - Do not leave
chmod 777orsetenforce 0in place as the fix.