How to solve the 403 Forbidden error in Nginx server

Source: Internet
Author: User
Tags 403 forbidden error nginx server

Nginx's 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, like 404,200 is not a technical error.

Which scenes need to return a 403 status code scenario?

1. The website prohibits specific users from accessing all content, for example: the site masks an IP access.

2. Access directory to prohibit directory browsing, example: Set AutoIndex off to access the directory.

3. User access to only intranet access files.

There are several common scenarios that need to return to 403 forbidden.

Because the server-side error configuration results in the desire not to

Returns 403 Forbidden when Nginx returns 403.

1. Permissions are not configured correctly

This is the most common reason why Nginx appears 403 forbidden.

To ensure that the files are executed correctly, Nginx requires both read access to the file and executable permissions for all of the files ' parent directories.

For example, when accessing/usr/local/nginx/html/image.jpg, Nginx requires both the Image.jpg file's readable permissions 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 the file to 644 permissions to avoid incorrect permissions.

2. Directory index Setup error (index directive configuration)

The web site root does not contain a file that is set by the index directive.

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

Index index.html index.htm index.php;

When you visit the Web site, Nginx looks for files in the root directory in index.html,index.htm, index.php order. If none of the three files exists, then Nginx will return to 403 forbidden.

If index.php is not defined in index, NGINX returns directly to 403 forbidden without checking to see if the index.php exists.

Also, if you run the JSP, Py needs to add index.jsp, to the Directory index instruction index.

Solution: Add the first file to the index directive, common is index.php,index.jsp,index.jsp or custom first page file.

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.