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

How to solve the 403 forbidden error reported by Nginx

王林
王林forward
2023-05-14 21:13:1115848browse

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; 
}

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

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

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

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete