Nginx 403 Forbidden: “(13: Permission denied)” and “directory index is forbidden”
Updated 24 November 2026 · By Brent Alexis
Short answer: a 403 from Nginx comes with one of two lines in the error log. directory index of "..." is forbidden means the folder Nginx serves has no index.html (or the file it's told to look for): point root at the folder that holds it. (13: Permission denied) means Nginx's user can't read the file or can't get through one of the folders above it: find the blocking folder with namei -l and give it o+x, files 644, folders 755. Never chmod 777: in the lab it didn't fix the problem.
Tested on the official nginx Docker image (Nginx 1.30.8) and Debian 12 (Nginx 1.22.1), with ProxyForge's own Config Generator output for a static site: 75 checks. SELinux can't run in containers, so that section isn't lab-tested. How it's tested
- Read the error log first
- “directory index of ... is forbidden”
- “(13: Permission denied)”
- Site in a home folder: a 404, not a 403
- Why not chmod 777
- RHEL, Alma, Rocky: SELinux
- 403s with a different log line
Read the error log first
The browser only says 403 Forbidden. Nginx writes the reason to its error log:
sudo tail -n 20 /var/log/nginx/error.log
(In the official Docker image the log goes to docker logs.) Match the line from the time of the 403:
| The error log says | Cause |
|---|---|
directory index of "/ | No index file in the folder Nginx serves |
open() "/ | Nginx's user can't read the file |
"/ | A folder in the path is closed to Nginx's user |
stat() "/ | Site in a home folder: the visitor gets a 404, not a 403 (below) |
access forbidden by rule | A deny line in the config |
All five lines were the same, word for word, on Nginx 1.30.8 and 1.22.1.
“directory index of ... is forbidden”
This is the server block from the Config Generator's output for a static site (HTTPS and Gzip unticked). It serves /var/www/example.com and looks for index.html there:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
With that config, three different mistakes all gave a 403 and the same log line, directory index of "/var/www/example.com/" is forbidden:
- The folder is empty. The files haven't been uploaded yet, or went somewhere else.
- The files are one folder down. A built app often puts its files in
dist/,build/orpublic/. Withindex.htmlin/var/www/example.com/dist/, the home page was a 403 while/dist/loaded. Changingrootto/var/www/example.com/dist;fixed it. - The index file has another name. With only
index.phpin the folder andindex index.html;in the config, Nginx has nothing to show. A PHP site needs the generator's PHP-FPM output, which usesindex index.php;.
Check what's really in the folder, then test and reload:
ls -la /var/www/example.com
sudo nginx -t && sudo systemctl reload nginx
Many answers suggest autoindex on;. It does make the 403 go away, but only by showing a list of every file in the folder. In the lab that list included a backup.sql file that anyone could then download. Fix the root or the index file instead.
“(13: Permission denied)”
Nginx's worker processes run as an ordinary user, not root. That user needs to read the file and enter (x permission) every folder on the way to it. Find the user in nginx.conf:
grep -E '^\s*user' /etc/nginx/nginx.conf
It said www-data on Debian 12 and nginx in the official image (nginx.org packages use nginx too; RHEL, Alma and Rocky packages also use nginx, not lab-tested).
Two cases from the lab, each a 403:
- The file isn't readable. With
index.htmlset to600and owned by root, the log saidopen() "/var/www/example.com/index.html" failed (13: Permission denied). - A folder is closed. With the site folder set to
700, the log said"/var/www/example.com/index.html" is forbidden (13: Permission denied). Note that it names the file, not the folder that's actually blocking it.
To find the folder that blocks it, namei -l lists the owner and permissions of every part of the path. Look for a folder without x in the last group:
namei -l /var/www/example.com/index.html
Then try reading the file as Nginx's user (the lab ran the same check with su). If this fails, Nginx fails too:
sudo -u www-data head -c 100 /var/www/example.com/index.html
Fix the permissions on the site (owner can write, everyone can read and enter), then reload:
sudo find /var/www/example.com -type d -exec chmod 755 {} +
sudo find /var/www/example.com -type f -exec chmod 644 {} +
Checked: both 403s became a 200 with 644 on the file and 755 on the folder.
Site in a home folder: a 404, not a 403
This one catches people because the error isn't a 403 at all. With root /home/brent/site;, the files readable, and /home/brent set to 750, the generator's config gave a 404 for a file that was there. The try_files line can't see past /home/brent, so Nginx treats the file as missing. The error log had one line:
[crit] stat() "/home/brent/site/" failed (13: Permission denied)
Without try_files, the same setup was a 403 with "/home/brent/site/index.html" is forbidden (13: Permission denied). Either way, namei -l /home/brent/site/index.html showed the blocker:
drwxr-x--- root root brent
That's the line to look for: r-x for the group, nothing (---) for everyone else, and Nginx's user is in neither.
Ubuntu has created new home folders as 750 since 21.04 (Ubuntu's release notes; the lab set it by hand). Two fixes:
- Move the site to
/var/www(the generator's default). This is the cleaner fix. - Or let other users pass through the home folder without listing it:
chmod o+x /home/brent. In the lab that turned the 404 into a 200, and the folder becamedrwxr-x--x, so other users still can't see what's in it.
Why not chmod 777
In the home-folder case, chmod -R 777 /home/brent/site changed nothing: the page was still a 404, because the folder blocking Nginx was /home/brent, one level up. 777 also lets every user and process on the server change your site's files. Find the one folder or file that's wrong and fix that.
RHEL, Alma, Rocky: SELinux
Not lab-tested (SELinux can't run in a container). On RHEL-family servers, a site outside /var/www can get (13: Permission denied) even when namei -l looks fine, because SELinux only lets Nginx read files labelled for web content. Check the label with ls -Z; for a site in /srv/example.com, label it and apply the label:
sudo semanage fcontext -a -t httpd_sys_content_t "/srv/example.com(/.*)?"
sudo restorecon -Rv /srv/example.com
A denial shows up in /var/log/audit/audit.log. If Nginx can't connect to your app (a 502 rather than a 403), that's a different SELinux setting: see the 502 guide.
403s with a different log line
access forbidden by rule: adenyline in the config refused it (the lab useddeny all;). Checkdenyandallowlines in the matchinglocationandserverblocks.- A real missing file is a 404. With the generator's
try_files, Nginx logs nothing for it; withouttry_files, the log saysopen() "/var/www/example.com/nope.html" failed (2: No such file or directory). - On Apache, a 403 logs
AH01630orAH00035instead: see Apache AH01630.
Generate a static-site Nginx config →
How to use ProxyForge · FAQ: common errors · Guides · What's new · About