Home > Operation and Maintenance > Nginx > How to solve the 403 forbidden error reported by Nginx

How to solve the 403 forbidden error reported by Nginx

王林
Release: 2023-05-14 21:13:11
forward
15929 people have browsed it

There are usually three situations that cause nginx 403 forbidden: one is the lack of index files, the other is permission issues, and the third is selinux status.

1. The index.html or index.php file is missing, which is the file specified in the index index.html index.htm line in the configuration file

server { 
 listen  80; 
 server_name localhost; 
 index index.php index.html; 
 root / var/www; 
}
Copy after login

If it is in /var When there is no index.php or index.html under /www, if you directly access the domain name and cannot find the file, 403 forbidden will be reported.

2. Permission issues. If nginx does not have permission to operate the web directory, a 403 error will also occur.

Solution: Modify the read and write permissions of the web directory, or change the startup user of nginx to the user of the directory, and restart nginx to solve the problem

chmod -r 755 / var/www
Copy after login

3. Set selinux to on (enabled) reason

First check the open status of selinux on the local machine. If the selinux status parameter is enabled, it is in the open state

/usr/sbin/ sestatus -v
Copy after login

Or use the getenforce command to check

to find the reason Now, how to turn off selinux?

1. Temporarily shut down (no need to restart)

setenforce 0

2. Modify the configuration file /etc/selinux/config and set selinux=enforcing Change to selinux=disabled

vi /etc/ selinux/config
Copy after login

Nginx报403 forbidden错误怎么解决

Note: Modifying the configuration file requires restarting the system reboot

**********If the above methods are not available If it cannot be solved, then there is one more thing you need to pay attention to *********

View nginx.conf:

user nobody

Change to: user root

Stop nginx -s stop

Restart nginx -c nginx.conf

The above is the detailed content of How to solve the 403 forbidden error reported by Nginx. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template