Static files permission issue in Nginx

If you encounter this kind of error by Nginx:

/xxx/yyy/colt.png" failed (13: Permission denied)

Then here's a check list for solving it quickly:


1) Assuming the user option in /etc/nginx/nginx.conf is www-data

# /etc/nginx/nginx.conf
user www-data;

2) The public directory which serves static files, say, /xxx/yyy/ must be www-data:www-data

sudo chown -R www-data:www-data /xxx/yyy

3) The path /xxx/yyy MUST NOT be /root/yyy, this point had wasted lot of my time to figure out

4) My suggestion is /var/www/yyy, and set permissions properly

# optional, my personal suggestion
sudo chown www-data:www-data /var/www

# required to do
sudo chmod 750 -R /xxx/yyy
sudo find /xxx/yyy -type f -print0 | xargs -0 chmod 640