Home  >  Article  >  Operation and Maintenance  >  How to solve Nginx 403 Forbidden error caused by permission issues

How to solve Nginx 403 Forbidden error caused by permission issues

WBOY
WBOYforward
2023-05-23 10:16:341487browse

Today I installed nginx in a new environment, and the results were all 403

权限问题导致Nginx 403 Forbidden错误怎么解决

Usually 403 is displayed and I immediately think that the path configuration is wrong, but I looked carefully After a while, the directory path is OK:

nginx.conf:

Copy code The code is as follows:

server {
listen 80;
server_name localhost ;

        #charset koi8-r;
                                                                                                                                                                                   # index index.html index.htm;
}
}

Path query results in the system:


Copy code The code is as follows:

[root@lizhong html]# ll /root/html/
Total usage 4

-rw-r--r-- 1 root root 3 April 18 11:07 index.html

directory exists, and the error persists after restarting nginx. Later, I thought about whether it was a permissions issue? So add a line to the head of nginx.conf:


Copy the code The code is as follows:

user root;

Restart nginx and access again, you can access normally

Restart nginx and access again, you can access normally


If you don’t want to run as root user, you can solve the 403 problem by modifying the directory access permissions. But you cannot put the directory in the root user's host directory. Put it in any location and give it 755, or change its owner through chown to be consistent with the nginx running identity to solve the permission problem.

The above is the detailed content of How to solve Nginx 403 Forbidden error caused by permission issues. 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