Home  >  Article  >  Operation and Maintenance  >  How to solve nginx 403

How to solve nginx 403

步履不停
步履不停Original
2019-06-21 13:36:4720793browse

How to solve nginx 403

I installed nginx through yum in a local virtual machine. The installation was normal, but the access times were 403,

So check the nginx log, the path is /var/log/nginx/error.log. Open the log and find the error Permission denied. The detailed error is as follows:

1. open() "/data/www/1.txt" failed (13: Permission denied), client: 192.168.1.194, server: www. web1.com, request: "GET /1.txt HTTP/1.1", host: "www.web1.com"

No permission? So I found a lot of information and can solve this problem through the following four steps. You may just have a problem with the previous configuration, and you may not necessarily use all four steps.

1. Due to the inconsistency between the startup user and the nginx working user

1.1 Check the startup user of nginx and find that it is nobody, but it is started with root

Command: ps aux | grep "nginx: worker process" | awk'{print $1}'

1.2 Change the user of nginx.config to be consistent with the startup user,

Command: vi conf/nginx.conf

2. 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.

1. server {

2. listen 80;

3. server_name localhost;

4. index index.php index.html ;

5. root /data/www/;

6. }

If there is no index.php, index.html under /data/www/, Direct file will report 403 forbidden.

3. 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

1. chmod -R 777 /data

2. chmod -R 777 /data/www/

4. The reason why SELinux is set to the open state (enabled).

4.1. Check the current status of selinux.

1. /usr/sbin/sestatus

4.2. Change SELINUX=enforcing to SELINUX=disabled state.

1. vi /etc/selinux/config

2.

3. #SELINUX=enforcing

4. SELINUX=disabled

4.3. Restart to take effect. reboot.

1. reboot

For more Nginx related technical articles, please visit the Nginx Tutorial column to learn!

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

Statement:
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
Previous article:Why does nginx appear 403Next article:Why does nginx appear 403