While developing apps running on Nginx, sometimes you may face this kind of error:
open() “/var/cache/nginx/” failed (13: Permission denied) while reading upstream error.
Investigating Nginx logs will show you something like this:
2015/07/25 11:37:44 [crit] 27955#0: *5607 open() "/var/cache/nginx/fastcgi_temp/7/01/0000000017" failed (13: Permission denied) while reading upstream, client: 220.127.116.11, server: yoursite.com, request: "GET /wp-admin/admin.php?page=theme_options HTTP/1.1", upstream: "fastcgi://unix:/tmp/php5-fpm.sock:", host: "yoursite.com", referrer: "http://yoursite.com/wp-admin/themes.php"
What causes the issue?
Most of the time, it’s caused by wrong file permissions or wrong ownership of the files/directories. When this happens, Nginx can’t read and write into those directories, and the result is that your information can not be displayed correctly.
How can you fix it?
The fix for this issue is simple. Try to change the owner of the cache directory:
chown nginx.nginx /var/cache/nginx/ -R
or if you are running Nginx as Apache user (nobody):
chown nobody.nobody /var/cache/nginx/ -R
If that doesn’t work, try removing the directories inside /var/cache/nginx/. Then, restart Nginx and it will automatically create the directories again:
service nginx restart