What are the correct permissions for my site that

2019-07-30 01:33发布

问题:

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

回答1:

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


标签: ubuntu nginx