The cause and solution of Nginx "403 Forbidden" error

Source: Internet
Author: User

Nginx 403 Forbidden Errors indicates that you are requesting a resource file but Nginx does not allow you to view it.
403 Forbidden is just an HTTP status code, which is not a technical error like 404,200.
What scenarios need to return a 403 status code scenario?

1. Websites prohibit certain users from accessing all content, for example: websites block an IP access.
2. Access directories that prohibit directory browsing, for example: set AutoIndex off to access the directory.
3. Users access files that can only be accessed by the intranet.

There are several common needs to return to the 403 Forbidden scenario.

Due to server-side misconfiguration, the 403 Forbidden is returned when you do not want nginx to return 403.

1. Permissions are not configured correctly

This is the most common reason for Nginx to appear 403 forbidden.

In order to ensure that the file can be executed correctly, Nginx needs both the Read permission of the file and the executable permission of all the parent directories of the file.

For example, when accessing/usr/local/nginx/html/image.jpg, Nginx needs both the Image.jpg file's readable permission and the/,/usr,/usr/local,/usr/local/nginx,/usr/ The local/nginx/html can execute permissions.

Workaround: Set all parent directories to 755 permissions and set file as 644 permissions to avoid incorrect permissions.

2. Directory index settings error (index directive configuration)

The site root directory does not contain files that are set by the index directive.

For example, a Web site that runs PHP usually configures index like this

Index index.html index.htm index.php;

When visiting the website, Nginx will find files in the root directory in the order of index.html,index.htm, index.php. If none of the three files exist, then Nginx returns 403 Forbidden.

If index.php is not defined in index, NGINX returns 403 forbidden without checking whether index.php exists.

Also, if you run the JSP, the PY needs to be added index.jsp, to the Directory Index Directive index.

Workaround: Add the home file to the index directive, often index.php,index.jsp,index.jsp or customize the home page file.

The cause and solution of Nginx "403 Forbidden" error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.