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,index.py 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