from https://stackoverflow.com/questions/25774999/nginx-stat-failed-13-permission-denied
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/staticIn 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 usernameand 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/staticFor your changes to work, restart nginx
nginx -s reload
If it works for you, you can keep it, but in my opinion, it may have some flaws.
It assigns the ownership of those directories to www-data, and gives that user access permission.
Our goal is to ensure that www-data can access the contents in that directory, but we also want to keep our own permission. However, your solution might prevent the current
$USER(yourself) from accessing that directory. It doesn't always happen, but it's probable.