Nginx user cannot access Ubuntu folder

I’m running Nginx on a Ubuntu server. Nginx does not have permission to access my project folder as show below.

sudo -u www-data stat /home/mainuser/projectname/
stat: cannot statx '/home/mainuser/projectname/': Permission denied

I know it’s an issue specific to this project folder and user because

sudo -u www-data stat /home/mainuser/


sudo -u mainuser stat /home/mainuser/projectname/

also runs fine.

I’ve been trying to follow this thread and so I’ve tried the following solutions… I tried setting

sudo chmod 755 /home/mainuser/projectname/


sudo chown -R :www-data /home/mainuser/projectname/

and when I run ls -l

I can see these permissions have been applied to the directory

total 4
drwxr-xr-x 7 mainuser www-data 4096 May 28 05:13 projectname

But still the Nginx www-data user does not have permissions to access the dir. What am I missing, how do I give this user access to this directory?