SoFunction
Updated on 2025-03-02

Nginx sets the access permissions of the directory to access static resources

Judging from the log information, it is indeed a Permission denied issue. We can recheck and set permissions to ensure that Nginx users have permission to access these files.

Check Nginx users:First, confirm that the user used by Nginx is usuallywww-dataornginx. You can find user information in the Nginx configuration file (usually in/etc/nginx/):

user www-data;

Set directory and file permissions:Assuming that the Nginx user iswww-data, we need to make sure that this user has read permissions to the directory and files:

sudo chown -R www-data:www-data /home/lighthouse/webapp/image/article/
sudo chmod -R 755 /home/lighthouse/webapp/image/article/

Check the permissions of the superior directory:Nginx users also need to have execution permissions on the superior directories to be able to access these directories:

sudo chmod 755 /home/lighthouse/
sudo chmod 755 /home/lighthouse/webapp/
sudo chmod 755 /home/lighthouse/webapp/image/

Restart Nginx service:After modifying permissions, restart the Nginx service to make the configuration take effect:

sudo systemctl restart nginx

After performing these steps, try to access the image file again. If the problem persists, please let me know and I will continue to troubleshoot it for you.

sudo chown -R lighthouse:www-data /home/lighthouse/webapp/image/article/

This is the article about access rights for Nginx to set up the directory to access static resources. For more information about access rights for Nginx directory, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!