Guides

NGINX 403 Forbidden: what it means and how to fix it step by step

Ubuntu 24.04 NGINX troubleshooting guide: causes of 403, verification commands, permission correction, and final testing with curl -I.

UptimeMag editorial team · 17 November 2026 · 4 min read

403 Forbidden su NGINX: cosa significa e come risolverlo passo per passo

A website returning 403 Forbidden does not have an NGINX problem: it has a permissions issue, a configuration issue, or a security module that NGINX does not control on its own. On Ubuntu 24.04 there are always five things to check. Here's how to isolate them one by one, with commands to run in order.

First step: read the error log, don't guess

Before touching permissions or configuration, the error log must be read:

sudo tail -f /var/log/nginx/error.log

then repeat the failing request (reload the page or re-run curl). NGINX writes the exact line in the log that explains the cause. The three most common variants are:

  • directory index of "/var/www/site/" is forbidden → a file index is missing from the folder and autoindex is disabled (the engine looks for files listed in the index directive: if none exist and autoindex is not on, the result is 403, not an empty list).
  • open() "/var/www/site/index.html" failed (13: Permission denied) → NGINX cannot read the file or one of the folders in the path: it's a Unix permissions issue or a security module issue.
  • access forbidden by rule → a deny directive in the configuration is blocking that IP address.

Each cause has a different fix: there's no point changing permissions if the log says the index is missing, and no point creating index.html if the log says permission denied.

Case 1: missing index file

Verify with:

ls -la /var/www/site

If there is neither index.html nor index.php, or if one exists but with a name different from the one declared in the index directive of the server block, the folder is treated as empty. There are two solutions: add the missing file, or explicitly enable directory listing with autoindex on; inside the relevant location block (use this only if the folder should genuinely be browseable, not in production on folders with sensitive content).

A case that often causes confusion: a try_files $uri $uri/ =404; block appears to return 404 when the file is missing, but if the URL points to an existing directory without an index, $uri/ causes the index module to resolve it anyway, which responds with 403 instead of 404. To get a clean 404 in that case use try_files $uri =404; or try_files $uri $uri/index.html =404;.

Case 2: wrong permissions on the document root

Check with:

ls -la /var/www/site
namei -l /var/www/site

The second command shows the permissions of each folder in the full path, from / to the document root: if even one intermediate folder lacks the execute bit for the user running NGINX (usually www-data on Ubuntu) the entire site will respond with 403, even if the document root itself is correct.

The correct values are:

sudo find /var/www/site -type d -exec chmod 755 {} \;
sudo find /var/www/site -type f -exec chmod 644 {} \;
sudo chown -R www-data:www-data /var/www/site

755 on folders (read, write and traverse for the owner, read and traverse for others) and 644 on files (read and write for the owner, read-only for others) are the minimum permissions that allow NGINX to read and traverse without opening unnecessary writes. Also verify the user running the process:

ps aux | grep nginx

On Ubuntu it is almost always www-data; if the site was uploaded by another user (a deploy via FTP, for example), ownership needs to be corrected with the chown command above.

Case 3: an allow/deny rule in the configuration

A log saying access forbidden by rule indicates a deny directive that is matching the client's address. According to the official documentation of nginx.org's ngx_http_access_module, rules are evaluated in sequence until the first match, and multiple allow/deny directives at the same level inherit from the parent level only if no other directives are defined at the current level. A typical block is:

location /admin/ {
deny 192.168.1.1;
allow 192.168.1.0/24;
deny all;
}

To find which file contains it, if the directive is not in the main server block:

sudo grep -rn "deny\|allow" /etc/nginx/

Often the offending deny all; is in a file included by another include, not in the vhost you are editing: search the entire /etc/nginx/ folder, not just the vhost file.

Case 4: AppArmor blocking NGINX even with correct permissions

On Ubuntu 24.04 AppArmor is active by default and can deny NGINX access even when Unix permissions are correct. Check with:

sudo aa-status

If the NGINX profile appears among those in enforce mode, denials are found with:

sudo dmesg | grep -i 'apparmor.*DENIED'

or in the kernel logs. If lines appear citing the NGINX binary and the document root path, the profile in /etc/apparmor.d/ needs to be updated to include that path, not disabled: disabling protection for the entire binary removes a security layer that normally helps contain potential web application exploits.

Configuration verification and final testing

Before reloading, always validate the syntax:

sudo nginx -t

The expected output is:

nginx: configuration file /etc/nginx/nginx.conf test is successful

Only then reload:

sudo systemctl reload nginx

and verify the error has gone with a request that shows headers only, without downloading the page body:

curl -I http://example.domain

A response of HTTP/1.1 200 OK confirms the problem is fixed. If 403 still appears, go back to the log (tail -f /var/log/nginx/error.log) and repeat the request: the line written at that moment indicates which of the four cases is still open.

Written with the help of artificial intelligence and checked by the editors (EU AI Act, art. 50).