How to solve the Nginx 403 Forbidden error caused by permission problem?

10-08-2023

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


Usually when I display 403, I immediately think that the path configuration is wrong, but I have a closer look and the directory path is ok:

nginx.conf:

The copy code code is as follows:

server { listen 80;  server_name localhost;   #charset koi8-r;   #access_log logs/host.access.log main;   location / {  root /root/html;   index  index.html  index.htm ; }}

Path query results in the system:

The copy code code is as follows:

user root;

1.jpg

Restart nginx and access it again, and you can access it normally

If you don't want to run with root user, you can solve the problem of 403 by modifying the directory access rights, but you can't put the directory in the root user's home directory, put it in any location and give it 755, or change its owner's identity with nginx's running identity through chown.

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us