Nginx: stat() failed (13: permission denied)
Solution 1:
Nginx operates within the directory, so if you can't cd
to that directory from the nginx user then it will fail (as does the stat
command in your log). Make sure the www-user
can cd
all the way to the /username/test/static
. You can confirm that the stat
will fail or succeed by running
sudo -u www-data stat /username/test/static
In your case probably the /username
directory is the issue here. Usually www-data
does not have permissions to cd
to other users home directories.
The best solution in that case would be to add www-data
to username
group:
gpasswd -a www-data username
and make sure that username
group can enter all directories along the path:
chmod g+x /username && chmod g+x /username/test && chmod g+x /username/test/static
For your changes to work, restart nginx
nginx -s reload
Solution 2:
Nginx need to have +x access on all directories leading to the site's root directory.
Ensure you have +x on all of the directories in the path leading to the site's root. For example, if the site root is /home/username/siteroot:
chmod +x /home/
chmod +x /home/username
chmod +x /home/username/siteroot
Solution 3:
I've just had the same problem on a CentOS 7 box.
Seems I'd hit selinux. Putting selinux into permissive mode (setenforce permissive
) has worked round the problem for now. I'll try and get back with a proper fix.
Solution 4:
On CentOS 7.0 I had this Access Deined
problem caused by SELinux and these steps resolved the issue:
yum install -y policycoreutils-devel
grep nginx /var/log/audit/audit.log | audit2allow -M nginx
semodule -i nginx.pp
Update: Just a side-note from what I've learned while using digitalocean's virtual Linux servers, or as they call them Droplets. Using SELinux requires a decent amount of RAM. It's most probably like you won't be able to run and manage SELinux on a droplet with less than 2GB of RAM.