File system directory permission issues may occur during nginx configuration

2021/06/23 19:48:51 [crit] 12553#12553: *29 stat() "/home/user/public/index.html" failed (13: Permission denied)
Copy the code

Nginx does not have permission to access /home/user/public. So how do you test that?

Sudo -u nginx stat /home/user/publicCopy the code

At this point, it is not possible to modify permissions simply by using the following command:

chomd -R 755 /home/user/public
Copy the code

The reason is that the /home/xxx directory is special and can be accessed only by users. Other accounts such as nginx cannot be accessed. The best solution is not unlimited zoom directory permissions, there are security risks.

A better way is to add your nginx account to the user group:

sudo gpasswd -a nginx user
Copy the code

Example Modify the access permission of a user group

chmod g+x /home/user && chmod g+x /home/user/public
Copy the code

This time in the execution of the above check permission instructions, to see if you can access.

Finally, re-nginx will do:

sudo nginx -s reload
Copy the code