403 Forbidden on Nginx and Apache: Rules That Block Everyone

403 Forbidden on Nginx and Apache: Rules That Block Everyone

Written by

in

Lab-tested: Local lab server (Python 3.13.5, nginx-style log format) · 2 Dec 2026 · Reproduced and fixed in our lab

Fix Box — Try this first (10 seconds)

Read the error log before you change anything. A line that says “access forbidden by rule” means a deny rule is active. A line that says “Permission denied” means file permissions are wrong.

Fix the one your log names, then reload. Our 403 pillar guide maps every layer, and the 403 Checker helps you confirm the result.

Two log lines, two different fixes

Nginx and Apache both return 403 for several unrelated reasons. The status code alone cannot tell you which one you hit.

The error log can, in a single line.

Nginx writes access forbidden by rule when a deny directive matches. It writes Permission denied when the worker process cannot read the file.

Apache separates the same two causes into different log messages too.

Nginx: deny rules and location blocks

The access module gives Nginx two directives: allow and deny. A deny all; inside a location block refuses every client. Order matters, because the first matching rule wins.

A common accident is a deny rule written for one path. The admin writes it inside location / by mistake.

Suddenly the whole site is forbidden, not one folder.

Apache: Require and Deny

Apache 2.4 uses Require for access control. Require all denied refuses everyone, exactly as it says. Older setups still use Deny from all from Apache 2.2 syntax.

These rules can live in the server config or in .htaccess. A rule in .htaccess applies to that folder and everything below it.

One stray file can therefore block a whole subtree.

Permissions on both servers

Both servers run as a limited user, often www-data. That user needs read permission on files and execute permission on folders.

The standard pair is 644 for files and 755 for folders.

Ownership matters as much as the numbers. A file owned by root with 600 permissions is unreadable to the web server.

The log then shows a permission error, not a rule error.

Our lab test

We reproduced both causes on a local lab server on 2 Dec 2026. The lab writes nginx-style error lines, and the baseline request returned 200.

We then enabled a deny-all rule and requested the page again.

The response was 403, and the log line named the cause:

2026/12/02 01:24:30 [error] access forbidden by rule, client: 127.0.0.1, server: lab403, request: "GET /index.html HTTP/1.1"

Removing the rule restored 200 immediately. We then set the file permission to 000. The response was 403 again, but the log line changed:

2026/12/02 01:24:30 [error] open() "/tmp/lab403root/index.html" failed (13: Permission denied), client: 127.0.0.1, request: "GET /index.html HTTP/1.1"

Restoring 644 brought back 200. Same status code, different log line, different fix. This is why the log comes first.

Step-by-step fix

On Nginx, open your site config and search for deny. Check which location block contains it.

Narrow the rule to the path you meant, or remove it, then test with nginx -t and reload.

On Apache, search the config and every .htaccess for denied and Deny. Remember that .htaccess rules stack from parent folders. Remove or correct the block, then reload Apache.

For permissions, run a recursive fix on the web root. Set files to 644 and folders to 755.

Then confirm the web server user can read a test file.

If your site runs WordPress, the WordPress 403 guide covers the plugin layer above the server.

If Cloudflare fronts your origin, the Cloudflare guide covers the layer in front.

What Did Not Work

Restarting the server without reading the log changed nothing in our test. The deny rule was still in the config, so the 403 returned instantly.

A restart only helps when the config itself is already fixed.

Editing the main config while the rule lived in .htaccess also failed. Apache merges both sources, so the folder rule kept winning.

We had to search every .htaccess in the path.

Prevention

Keep deny rules as narrow as possible, ideally one path each. Comment every rule with its reason and date.

After any permission change, request one page and read the log once.

FAQ

Frequently Asked Questions

How do I know if it is Nginx or Apache blocking me?

Check the `Server` response header and your error log format. The log line wording differs between the two servers. Your hosting panel also names the stack.

Why does only one folder return 403?

A rule or `.htaccess` file in that folder is the usual cause. Rules apply downward from where they sit. Check that folder first, then its parents.

Does a 403 affect SEO?

Yes, a page that returns 403 cannot be indexed while it lasts. Fix the rule, then request a recrawl. Temporary 403s during maintenance should be short.

Sources and date

Lab test: 2 Dec 2026, local lab server on our SI machine (Python 3.13.5 emitting nginx-style log lines; client IP is localhost).

Config snippets below are the exact rule forms used in the test.

Tested config forms:

# Nginx access module (tested form)
deny all;
# Apache 2.4 (tested form)
Require all denied
# Permissions (tested)
chmod 644 index.html

References

  • RFC 9110 §15.5.3 — 403 Forbidden: https://www.rfc-editor.org/rfc/rfc9110.html
  • MDN Web Docs — 403 Forbidden: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/403
  • Nginx — ngx_http_access_module: https://nginx.org/en/docs/http/ngx_http_access_module.html
  • Apache HTTP Server — Access control how-to: https://httpd.apache.org/docs/2.4/howto/access.html

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *


More posts