Free auditStart free
GuideError · HTTP status codes

403 Forbidden in nginx

Trace an nginx 403 to its cause: allow/deny rules, auth_request, referer checks, missing index files or worker permissions. Includes config examples.

5 min
read
11
sources
Oct 23, 2026
updated
Scaplet Editorial Team
author
The short answer

An nginx 403 means nginx, or an app behind it, refused the request. In nginx itself the usual causes are allow and deny rules, an auth_request subrequest answering 403, a referer check that returns 403, a directory with no index file and autoindex off, or files the worker user can't read. Read the error log for the line that names the cause.

  1. Why does nginx return 403?
  2. Access rules: allow, deny and satisfy
  3. Index files, autoindex and file permissions
  4. Find the cause in two minutes
  5. What it does to SEO
30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
01nginx causes of a 403 and where to look

Why does nginx return 403?

A 403 means the server understood the request and refused it (see 403 Forbidden). In nginx, the refusal is configured in a handful of places. Check them in this order, because the first ones are the most mechanical.
Cause

allow and deny rules

What the nginx docs say
Rules are checked in sequence until the first match
What to check
The location block and its parents; the order of allow and deny; a final deny all
Cause

Inherited access rules

What the nginx docs say
allow and deny are inherited from the previous level only if the current level defines none
What to check
A new allow or deny in a location silently replaces the server-level rules
Cause

Address and password rules combined

What the nginx docs say
satisfy defaults to all, so every access module must allow the request
What to check
Add satisfy any if either an IP match or a password should be enough
Cause

auth_request

What the nginx docs say
A subrequest answering 401 or 403 denies the access with that code
What to check
The auth service's response for this request
Cause

Referer check

What the nginx docs say
The referer module example uses return 403 when $invalid_referer is set
What to check
valid_referers list; browsers may not send the Referer header
Cause

No index file, autoindex off

What the nginx docs say
index defaults to index.html; autoindex defaults to off, and a request usually reaches it when no index file is found
What to check
The index directive, the file on disk, and whether you want a listing
Cause

Worker user cannot read the files

What the nginx docs say
The user directive defines the credentials used by worker processes
What to check
The user and group in the main context against file and directory permissions
Cause

The proxied application

What the nginx docs say
nginx passes the upstream's 403 on
What to check
The upstream's own logs

Every row comes from the nginx documentation for the named module, except the last, which is simply what a reverse proxy does with an upstream response. The error log usually names the check that refused the request. For a directory with no index file, nginx's source logs directory index of "/path/" is forbidden.

02Check it

Access rules: allow, deny and satisfy

The access module limits access to certain client addresses. Its own example shows the rule order that matters:

Per the docs, access is allowed only for those networks, excluding 192.168.1.1. Put the specific rules first and deny all last. If you reach the end with deny all, anyone not listed is refused.

When you protect a path by both address and password, the satisfy directive decides how they combine. The default is all, so a visitor must pass every check. This example allows a visitor who either comes from the allowed address or supplies a valid password:

satisfy any: IP match or password
location / {
    satisfy any;
    allow 192.168.1.0/32;
    deny  all;
    auth_basic           "closed site";
    auth_basic_user_file conf/htpasswd;
}
allow and deny are checked top to bottom
location / {
    deny  192.168.1.1;
    allow 192.168.1.0/24;
    allow 10.1.1.0/16;
    allow 2001:0db8::/32;
    deny  all;
}
03Explained

Index files, autoindex and file permissions

A request ending in a slash is handled by the index module, which looks for the files named in index (default index.html). The nginx docs say a request usually goes on to the autoindex module when no index file is found. That module produces a directory listing, but autoindex is off by default. With no index file and the default settings, no handler serves the request, and nginx's source returns 403 and logs directory index of "/path/" is forbidden. Either add the index file or turn the listing on for that location only:

Serve a listing for one location
location /downloads/ {
    autoindex on;
}

The index module also does an internal redirect, so the request can be processed in a different location from the one you expected. A location = / block with index index.html sends "/" to the second location as "/index.html". Check the location that finally handles the request, not only the first.

File permissions come last. When nginx can't open a file because of permissions, it returns 403 and the error log line ends in (13: Permission denied) on Linux. Worker processes run as the user set by the user directive (the default is nobody). That account needs execute permission on every directory in the path and read permission on the file. Test it as that user:

Check the path as the worker user
# Show owner and mode for every component of the path
namei -l /var/www/example/index.html

# Try to read the file as the worker user (replace www-data)
sudo -u www-data cat /var/www/example/index.html

namei is part of util-linux; the account name varies by distribution. Look at the user line in nginx.conf for yours.

04How it works

Find the cause in two minutes

  1. 1

    Confirm nginx answered

    Request the URL with a header dump and compare it to a direct request to the upstream. A 403 only through nginx is an nginx rule.

  2. 2

    Read the error log

    Open the file set by error_log in your configuration (default logs/error.log, level error). The lines above are logged at the error level, so the default setting shows them.

  3. 3

    Match it to a row in the table

    Access rule, auth_request, referer, index, or permissions. Change only that one.

  4. 4

    Reload and retest as the real client

    Reload nginx after the change, then retry with the same IP, Referer and credentials the failing client used.

You can also customize what visitors see. error_page 403 /forbidden.html serves a page of your choice, and the nginx docs show the same directive with a full URL, such as error_page 403 http://example.com/forbidden.html. That changes the page, not the cause.

05Explained

What it does to SEO

Google treats every 4xx other than 429 the same way: the URL is dropped from the index if it was indexed. It also says that 401 and 403 have no effect on crawl rate, so don't use them to slow Googlebot. If an allow or deny rule or a referer check is refusing crawlers, those pages leave the index. See 4xx errors. If the 403 comes from a CDN in front of nginx instead, see 403 Forbidden.
Questions

Asked a lot.

4 questions people ask next, answered from the sources on this page.

01Why do I get 403 Forbidden on nginx for a directory?

The index module looks for an index file (default index.html). Without one, the request usually falls to the autoindex module, which is off by default, and nginx answers 403. Add the index file, set the index directive to the file you have, or enable autoindex for that location.

02How do I fix an nginx 403 permission error?

Worker processes use the user and group set by the user directive. Make sure that account can read the file and traverse every directory above it, then check the error log for the line that names the cause.

03What is the difference between nginx 401 and 403?

The auth_basic module returns 401 with a Basic challenge when credentials are missing or wrong. A 403 comes from refusals such as allow and deny rules, an auth_request subrequest returning 403, or a referer check using return 403.

04Why does nginx return 403 after I added password protection?

satisfy defaults to all, so an address rule and a password must both pass. Add satisfy any if either one should be enough, and check that deny all isn't refusing the visitor first.

Sources · 11

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • rfc-editor.org
  • nginx.org
  • github.com
  • google.com
  1. 01RFC 9110: HTTP Semanticsrfc-editor.org · checked 2026-10-25
  2. 02Module ngx_http_access_module - nginx documentationnginx.org · checked 2026-10-25
  3. 03Module ngx_http_index_module - nginx documentationnginx.org · checked 2026-10-25
  4. 04Module ngx_http_autoindex_module - nginx documentationnginx.org · checked 2026-10-25
  5. 05Core functionality (user directive) - nginx documentationnginx.org · checked 2026-10-25
  6. 06Module ngx_http_core_module (satisfy) - nginx documentationnginx.org · checked 2026-10-25
  7. 07Module ngx_http_auth_request_module - nginx documentationnginx.org · checked 2026-10-25
  8. 08Module ngx_http_referer_module - nginx documentationnginx.org · checked 2026-10-25
  9. 09Module ngx_http_auth_basic_module - nginx documentationnginx.org · checked 2026-10-25
  10. 10nginx source: ngx_http_core_module.c and ngx_http_auth_basic_module.c (GitHub)github.com · checked 2026-10-25
  11. 11How HTTP status codes affect Google's crawlersdevelopers.google.com · checked 2026-10-25
Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane