Nginx can't serve static file from home directory

ng flag

I have a index.html file in both locations /home/ubuntu/web/build and /var/www/html

There is no other complicated rules.

However only root /var/www/html works!

        # root /home/ubuntu/web/build; fails!
        root /var/www/html; # works!
        index index.html;

        location / {
                autoindex on;
                try_files $uri $uri/ =404;

Here are the permissions

f: /var/www/html
 drwxr-xr-x root root /
 drwxr-xr-x root root var
 drwxr-xr-x root root www
 drwxr-xr-x root root html

f: /home/ubuntu/web/build
 drwxr-xr-x root   root   /
 drwxr-xr-x root   root   home
 drwxr-x--- ubuntu ubuntu ubuntu
 drwxrwxr-x ubuntu ubuntu web
 drwxrwxr-x ubuntu ubuntu build
Richard Smith avatar
jp flag
The user which runs Nginx needs to have read access to every directory in the path. I can see that the `ubuntu` folder is only accessible by the `ubuntu` user and the `ubuntu` group.
cn flag

Nginx runs as nginx user, hence it should have read permissions to all the directories in the path. /home/ubuntu is owned by the ubuntu user and ubuntu group, so the third group of permisisons (because nginx user is not in the ubuntu group`) describes access to the directory. There are two solutions:

  • Add read permissions to all users to the /home/ubuntu directory (not recommended)
  • Add nginx user to ubuntu group

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.