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

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 saysCause
directory index of "/var/www/example.com/" is forbiddenNo index file in the folder Nginx serves
open() "/var/www/example.com/index.html" failed (13: Permission denied)Nginx's user can't read the file
"/var/www/example.com/index.html" is forbidden (13: Permission denied)A folder in the path is closed to Nginx's user
stat() "/home/brent/site/" failed (13: Permission denied)Site in a home folder: the visitor gets a 404, not a 403 (below)
access forbidden by ruleA 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:

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:

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:

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

Generate a static-site Nginx config →

How to use ProxyForge · FAQ: common errors · Guides · What's new · About