Fix 403 forbidden error in Nginx server

  

403 Forbidden errors for nginx means 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 scene with a 403 status code?

1. The website prohibits specific users from accessing all content. For example, the website blocks an ip access. 2. Access the directory that prohibits directory browsing. For example, set autoindex off to access the directory. 3. The user accesses files that can only be accessed by the intranet.

There are several common scenarios where you need to return to 403 Forbidden.

Due to server-side misconfiguration, 403 Forbidden is returned when you don't want

nginx returns 403.

1. Permission configuration is incorrect

This is the most common reason why nginx appears 403 forbidden. In order to ensure that the file can be executed correctly, nginx requires both the read permission of the file and the executable permission of all parent directories of the file. For example, when accessing /usr/local/nginx/html/image.jpg, nginx requires both readable permissions for the image.jpg file and /, /usr, /usr/local, /usr/local/nginx, /Usr/local/nginx/html can execute permissions. Solution: Set all parent directories to 755 permissions, and set the file to 644 permissions to avoid incorrect permissions.

2. Directory index setting error (index directive configuration)

The website root directory does not contain the file set by the index directive. For example, a website running PHP is usually configured like this index index index.html index.htm index.php;

When accessing the site, nginx will follow index.html, index.htm, index.php The order of the files in the root directory. If none of these three files exist, nginx will return 403 Forbidden.

If index.php is not defined in index, nginx returns 403 Forbidden directly and does not check if index.php exists. Similarly, if you run jsp, py also need to add index.jsp, index.py to the directory index directive index. Solution: Add the home page file to the index directive, which is usually index.php, index.jsp, index.jsp or a custom home page file.

Copyright © Windows knowledge All Rights Reserved