1
votes

I am running a web server on Nginx 1.14.0 (Ubuntu 18.04, php-fpm 7.1.25) on my SSD system drive (/dev/sda5, ext4) and everything works just fine.

And I tried to move my web-server dir to another HDD (/dev/sdb1, ext4) in my computer to free up some space on my SSD. So I copied /var/www/html directory to /media/myhdd/newhtml and preserved the owner and permissions of the original directory. All was copied OK.

And when I try to open web server from new dir (/media/myhdd/newhtml), I get 403 Forbidden (nginx error log: 13: Permission denied) error.

I checked permissions for my new dir and restarted nginx a hundred times already. Permissions are the same as my /var/www/html dir and are set to 755 recursively.

chown -R myusername:www-data /media/myhdd/newhtml chmod -R 755 /media/myhdd/newhtml

I even tried to simplify things and output directory listing.

This works and outputs directory listing, as expected:

server {

    listen 80;
    listen [::]:80;

    root /var/www/html;

autoindex on;

    server_name localhost;

charset UTF-8;


}

this DOES NOT WORK, and gives FORBIDDEN 403 error:

server {

    listen 80;
    listen [::]:80;

    root /media/myhdd/newhtml;

autoindex on;

    server_name localhost;

charset UTF-8;


}

since permissions for both directories are the same, I expect nginx to list dirs from /media/myhdd/newhtml, as it does for /var/www/html

please share your ideas about what might cause this unexpected result? Thanks.

1

1 Answers

1
votes

I've figured it out. I changed group of the mount directory of my HDD, which in my case was /media/myhdd. It was set to myusername. And I changed it to www-data, and it worked! And what's interesting, I did not touch inside files.

So probably, child directories somehow depend on highest parent's permissions, and somehow inherit them. Even though permissions to the target directory inside the parent are already set approprietly.

Hope it helps someone as well!

Thanks everyone!