What the message looks like
directory index of "/var/www/site/" is forbidden, client: 198.51.100.7, server: example.com, request: "GET / HTTP/1.1"Common causes
- The directory has no index file and
autoindexis off (“directory index … is forbidden”). indexdoes not listindex.phpalthough the app runs on PHP.- The nginx user lacks execute (x) on a parent directory or read on the file (“13: Permission denied”).
denyorallowrules block the client IP (“access forbidden by rule”).- Wrong SELinux context, e.g. after
mvfrom a home directory.
Check
- Find the exact reason in error.log
tail -n 30 /var/log/nginx/error.log | grep -E 'forbidden|Permission denied|access forbidden' - Show permissions along the whole path
namei -l /var/www/site/index.html - Test as the nginx user whether the file is readable
sudo -u www-data cat /var/www/site/index.html >/dev/null && echo ok - Show root, index and access rules in the active config
nginx -T 2>/dev/null | grep -nE '^\s*(root|index|autoindex|deny|allow|auth_basic) '
Fix
- Create an index file or set
index index.php index.html;in the server block. - Give directories 755, files 644 and the right owner; every parent directory needs x for the nginx user.
- With SELinux restore the context:
restorecon -Rv /var/www/site. - Review deny/allow rules, especially in
locationblocks that match several paths. - After changes run
nginx -t && systemctl reload nginx.
Typical scenario
A developer rsyncs a static build to the server and gets '403 Forbidden' on the home page. The error log says 'directory index of /var/www/site/ is forbidden'. The build, however, sits in a dist/ subfolder, the root has no index.html, and autoindex is off. First run ls -la on the document root to see whether the index file is where it should be, before you change permissions or nginx rules.
FAQ
What is the difference between 401 and 403?
401 means authentication is missing or invalid – with credentials it may work. 403 means the server refuses access regardless of login.
Should I enable autoindex to get rid of the 403?
Only if you really want a file listing. Otherwise add an index file – autoindex exposes every file in the directory.
How does 403 differ from 401 and 404?
401 asks for authentication, 404 says the resource does not exist. 403 means the server understood the request but refuses it, for example because of missing permissions, a missing index file or a deny rule. The error log tells you which case applies.
Why do I get a 403 although the file permissions are right?
On systems with SELinux the file context (httpd_sys_content_t) may be missing, and SELinux then blocks access despite correct Unix permissions. A parent directory without execute permission for the nginx user is enough as well. namei -l shows each level.
Should I set autoindex on to make the 403 go away?
Usually not. It makes the directory contents publicly listable, which can expose backups, configuration leftovers or drafts. It is better to provide the missing index file or point the root at the right directory.