[Django]-Open() "/root/project/static/*.css" failed (13: Permission denied) nginx

13πŸ‘

βœ…

The problem I am guessing is the fact that your project root directory is at /root. The default permissions for /root are:

drwx------ 14 root root 4096 May 8 12:47 root

As you can see, other users, such as www-data don’t even have read access to the /root directory. In Linux FS, if you need to read something at a path/a/b/c, you need to have read access to each of the folders in that path.

The Nginx worker process runs as user www-data which is trying to open a file that is rooted at /root where this user does not have read permissions, and therefore raising a Permission denied (13).

See this demo for more detail:

$ cat /root/test2/text.txt     
cat: /root/test2/text.txt: Permission denied
$ sudo cat /root/test2/test.txt  
A
$ sudo ls -la /root/ | grep test2
drwxrwxrwx   2 root     root       4096 May 24 02:04 test2

Hope this makes sense. The solution would be on of the following:

  • Run nginx workers as root (not recommended)
  • Move your project directory to a location that is designed to be accessed by multiple users such as /usr/local/share or /var/www/ (recommended)

1πŸ‘

I have the same problem. My nginx server on Centos 7.6 can’t access to static folder in path /home/user/app/mysyte/static/. In /var/log/nginx/error.log same error open() "/home/user/app/mysyte/static/*.css" failed (13: Permission denied)

For solving this problem look at this page issue 2

0πŸ‘

i was running into the same problem and i found this answer useful!

Nginx connet to .sock failed (13:Permission denied) – 502 bad gateway

What I simply did was changing the name of the user on the first line in /etc/nginx/nginx.conf file.

In my case the default user was www-data and I changed it to my root machine username.

0πŸ‘

As @rtindru said the solution to the problem is to move your project directory to a location that is designed to be accessed by multiple users such as /usr/local/share or /var/www/.
Here is a resource on how to do that
the source

I had a similar issue of loading my static files and here are the commands i used to change.

sudo rsync -av /home/ubuntu/MyBlog/firstproject/static /var/www/

Where MyBlog/firstproject is the directory to my project. Remember to only change the static directory.

sudo nano /etc/nginx/sites-enabled/myproject

myproject is the directory created for ngnix.
add the following lines

server {

        root /var/www/static;
   
        . . .
}

And now restart the ngnix as suggested from source. Hope this works.

Leave a comment