Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

nginx 403 Forbidden: "directory index of ... is forbidden" and "Permission denied" in the error log

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

When nginx answers 403 Forbidden, the error log says why, in one of three wordings. directory index of "/path/" is forbidden means the URL ends in a slash, no index file was found and nothing is allowed to list the directory. A line ending (13: Permission denied) means the file or directory exists but the nginx worker user is not allowed to read it or search the path to it. Read the log line first; the fixes differ.

What the error means

In the nginx 1.30.6 source there are three places that produce a 403 for static files, each with its own log text:

  1. No index file and no listing. For a request URI ending in /, when no handler produced a response, the core module logs directory index of "%s" is forbidden, with no error number, and returns 403.
  2. Index file not readable. The index module tries each file in the index list. If opening one fails with a permission error, it logs "%s" is forbidden, followed by (13: Permission denied), and returns 403.
  3. A file not readable. The static file module logs open() "%s" failed (13: Permission denied) and returns 403 for permission errors. The same code returns 404 for a missing file.

The nginx source adds an operating system error number and its text to these lines. The wording after the number is the operating system's, not nginx's: the Linux errno(3) manual page lists the error name EACCES with the text "Permission denied (POSIX.1-2001)." The same page says numeric values are not part of its list because they "vary across UNIX systems, and even across different architectures on Linux". Its errno -s permission example prints "EACCES 13 Permission denied", which is the number seen in nginx logs on Linux.

Two directives decide the first case. The nginx documentation says index has the default index index.html; and "Files are checked in the specified order". The autoindex directive "Enables or disables the directory listing output" and its default is autoindex off;. The autoindex page adds that a request usually reaches it when the index module "cannot find an index file". So a site whose home page is index.php, with index left at its default, answers 403 on /.

For the permission cases, the workers run as the user named by the user directive, whose default is user nobody nobody;. That user needs execute (search) permission on every directory on the path and read permission on the file. The chmod manual describes the x permission as "execute (or search for directories)". Reading is not enough: a mode such as drwx------ on a parent directory blocks everyone but its owner.

Likely causes

Cause What you see in the error log How to confirm
No file in the index list exists in the directory directory index of "/var/www/app/public/" is forbidden nginx -T shows the index value; ls shows what the directory holds
The index file exists but the worker cannot open it "/var/www/app/public/index.html" is forbidden (13: Permission denied) namei -l on that path shows the modes of each part
A parent directory blocks the worker user open() "/var/www/app/public/style.css" failed (13: Permission denied) namei -l shows a directory without search permission for the worker user
Wrong root or alias The path in the log is not where the site's files are nginx -T shows the root used by that location
SELinux label on the files The same lines, though normal permissions look correct ls -Z shows a type other than the one the policy expects
Directory listing wanted but off The first wording, and you want a listing autoindex is absent or off

Prove the cause before changing anything

All of these are read-only.

1. Read the log line. The error_log default is error_log logs/error.log error; and nginx -T prints the configuration so you can find the real path. Match the wording to the table.

2. Read the configuration.

nginx -T

Find the server and location for the failing URL. Note the root or alias, the index list, any autoindex, and the user directive in the main context.

3. Show what is on disk.

ls -l /var/www/app/public/

For the first wording, look for a file named in your index list.

4. Follow the permissions along the whole path.

namei -l /var/www/app/public/index.html

The namei manual says -l is the long listing format, the same as -m -o -v: it shows each path component's mode bits and owner. Look for a directory without the execute bit for the worker's user or group, and a file without the read bit.

5. If SELinux is enforcing, show the labels.

ls -Z /var/www/app/public/
restorecon -n -v -R /var/www/app/public

ls -Z prints "any security context of each file". For restorecon, -n means "don't change any file labels (passive check)" and "To display the files whose labels would be changed, add -v". The httpd_selinux manual page says to "Set files with httpd_sys_content_t if you want httpd_sys_script_exec_t scripts and the daemon to read the file". For the audit-log side of SELinux denials, see "SELinux blocks the web server: "avc: denied", httpd_can_network_connect and port labels".

Fix

Disruptive step: every change below alters live behaviour. For nginx configuration, save a copy outside any directory your configuration includes by wildcard, so the copy is not loaded as a second configuration:

cp -p /etc/nginx/conf.d/app.example.com.conf /root/app.example.com.conf.2026-11-20

Then edit the file, check it, and only then reload:

nginx -t
nginx -s reload

The nginx manual says -t tests the configuration "for correct syntax" and tries "to open files referred in the configuration", and that reload starts "the new worker process with a new configuration" and gracefully shuts down the old ones. To back out, restore the saved copy under the name you saved it, check it, and reload:

cp -p /root/app.example.com.conf.2026-11-20 /etc/nginx/conf.d/app.example.com.conf
nginx -t
nginx -s reload

No index file matches

Add the file your site really uses to the index list, for example index index.php index.html;, in the server or location block. If your site uses PHP and the 403 turns into a 404 or a blank page afterwards, see nginx and PHP-FPM "Primary script unknown" / "File not found.": SCRIPT_FILENAME and root. If you want a listing, autoindex on; turns one on.

Risk: autoindex on exposes every file name in the directory to anyone who can load the URL. Use it only on directories meant to be listed. To back out, remove the line or set autoindex off;, then check and reload as above.

Permission denied on a file or parent directory

Record the current modes first, using the output of step 4, and save it:

namei -l /var/www/app/public/index.html > /root/namei-before.2026-11-20.txt

Also record the mode of the directory you are about to change:

namei -l /home/deploy > /root/namei-home-deploy-before.2026-11-20.txt

Risk: adding search permission for others on /home/deploy, as in the example below, lets every local user pass through it, not only nginx. A narrower choice is to put the worker user in a group that owns the web files and give that group the access. Keeping web content outside home directories avoids the problem.

Then fix the one component that blocks the worker. For example, if /home/deploy is drwx------ and the worker user is not its owner, adding search permission for others lets nginx pass through it:

chmod o+x /home/deploy

The chmod manual describes the symbolic form: + adds the selected permission bits to the existing mode.

To back out, first read /root/namei-home-deploy-before.2026-11-20.txt. If it shows that others already had the execute bit, leave it alone; if not, remove the bit you added:

chmod o-x /home/deploy

SELinux label

If restorecon -n -v lists files that would change, those labels differ from what the policy says. Record the current labels first:

ls -Z -R /var/www/app/public > /root/labels-before.2026-11-20.txt

Risk: for the restorecon -R command below, the manual says that if a file has a context, restorecon "will only modify the type portion of the security context", and a file labelled with a customizable type is left alone unless -F is used. Relabelling can also change how other services read those files.

Then apply the policy's labels. This command covers the whole tree under that path, not only the files restorecon -n -v listed:

restorecon -R -v /var/www/app/public

To back out, set the type recorded in the saved listing, naming the type from that file:

chcon -R -t RECORDED_TYPE /var/www/app/public

RECORDED_TYPE stands for the type shown in labels-before. The chcon manual defines -t as "set type TYPE in the target security context" and -R as recursive. This only restores a uniform tree. If different files had different types, restore each one separately.

Example (illustrative): app.example.com on web01 uses root /var/www/app/public;. A request for / returns 403 and the error log reads directory index of "/var/www/app/public/" is forbidden. ls -l shows the directory holds index.php and no index.html, and nginx -T shows no index directive, so the default index.html applies. The administrator saves the configuration to /root, adds index index.php index.html; to the server block, runs nginx -t, then nginx -s reload. The 403 is gone and PHP now answers.

Confirm the fix

  1. Request the same URL again with curl -sI https://app.example.com/ and check the status line is no longer 403. -I fetches headers only.
  2. The error log shows no new is forbidden or Permission denied lines for that URL.
  3. A deep URL and a static file such as a stylesheet also load, so you know the whole path is open, not only the index file.
  4. If you changed permissions, compare namei -l with the saved listing to confirm only the intended bit changed.
  5. If you relabelled files, restorecon -n -v -R on the same path now lists nothing.

What to watch afterwards

  • Alert on new Permission denied lines in the nginx error log after deployments. A deployment tool that changes owners or modes shows up here first.
  • After you change how files are deployed, such as a new user, a new directory or a container mount, run namei -l again on one file.
  • Keep the index list in step with the framework you deploy, so a change of entry file does not give a 403.
  • Do not leave autoindex on in place longer than needed.

Risks and limits

  • These commands have not been run or lab-tested.
  • The nginx log wording was read from the 1.30.6 source. Other versions may differ. The download page now lists 1.30.7 as stable.
  • A 403 can also come from an allow or deny rule, authentication, or an application. Those cases are not covered here.
  • The httpd_selinux page describes httpd. Whether your nginx worker runs in the same SELinux domain depends on your distribution's policy; the audit log is the way to know.
  • The paths, user and file names above are examples. Use the ones from your own nginx -T output.

Sources