What are the correct permissions for my site that is now served by NginX?

14,605

You have wrong permission for subdir1, fix it:

chmod 755 /home/user/Dropbox/subdir1

or even better (recursive):

find /var/www/example.com -type d -print0 | xargs -0 chmod 755

As for nginx user, you can set it with user configuration directive:

user www-data;

You can use any user with NGINX server, you just need correct permissions for folders (755) and files (644) of your project. I prefer distinct user nginx, it is good practice, but not necessary.

You can create system nginx user in Ubuntu/Debian like this:

sudo adduser --system --no-create-home --disabled-login --disabled-password --group nginx
Share:
14,605
Questioner
Author by

Questioner

Updated on June 04, 2022

Comments

  • Questioner
    Questioner almost 2 years

    I am running a local testing server on my laptop running Ubuntu 16.10. I was running Apache2, but I've decided to switch over to NginX. Following guides like this one, I think I've got NginX up and running, along with PHP 7.0 fpm.

    However, when I load one of my sites, I get a 403 Forbidden error. The NginX error log says :

    [error] 14107#14107: *1 directory index of "/var/www/example.com/" is forbidden, client: 127.0.0.1, server: example.com, request: "GET / HTTP/1.1", host: "example.com"
    

    I understand that all the parent directories in the path should have the right permissions, but I'm unclear on exactly what the correct permissions are. If I understand correctly, under Apache2, the directories were accessible to the user or group www-data, but I'm not sure if that's still true under NginX.

    What chmod or chown command should I be using to ensure that the relevant directory has permissions that will make it accessible to NginX? Note that I am completely replacing Apache2 with NginX, so there is no need to preserve any settings for Apache's sake.

    Also, for reference, here is the current directory path and permissions of my site. Note that the directory in /var/www is a symlink to a directory in my Dropbox folder, if that has any impact.

    $ namei -om /var/www/example.com
    f: /var/www/example.com
     drwxr-xr-x root     root     /
     drwxr-xr-x root     root     var
     drwxr-xr-x www-data www-data www
     lrwxrwxrwx www-data www-data example.com -> /home/user/Dropbox/subdir1/subdir2/Site/
       drwxr-xr-x root     root     /
       drwxr-xr-x root     root     home
       drwxr-xr-x user     user     user
       drwx--x--x user     user     subdir1
       drwxrwxr-x user     user     subdir2
       drwxr-xr-x user     user     Web
       drwxr-xr-x user     user     Site
    
  • Questioner
    Questioner over 7 years
    Thank you for responding. I tried your find command, but it returned chmod: missing operand after ‘755’. I tried to then manually set each directory to 755, but I'm still getting the permission denied error. I created an nginx user with the command you suggested, but I'm having a hard time figuring out the user configuration directive, so I haven't managed to implement the nginx user in any meaningful way.
  • Questioner
    Questioner over 7 years
    The problem may not be permissions after all (though maybe permissions are still related). I have asked a new question based on my current situation here.
  • Questioner
    Questioner over 7 years
    There were actually a few settings problems, which got solved in the other question I referenced, but, the permissions issue was solved here, so thank you for the help.