Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access forbidden to folders in /Users/user/ on Monterey

I am trying to setup nginx on an Apple silicon mac with MacOs Monterey.

Nginx has been installed with brew

If I edit the config file (/opt/homebrew/etc/nginx/nginx.conf) to set a new root directory, it works if I point it at a folder that is not associated with my user folder. For example

location / {
    root   /var/www/sites;
    index  index.html index.htm index.php;
}

However, if I set root to a folder in my home directory, e.g

location / {
    root   /Users/name/sites;
    index  index.html index.htm index.php;
}

I get a 403 Forbidden error.

Although this seems to be a common setup, lots of tutorials say to put your various sites in /User/username/Sites.

I've tried changing the permissions with chmod 755 sites and I've tried changing the owner of the sites directory to the root user. However none of these worked. I had similar issue when trying to setup apache.

Any ideas what I'm doing wrong with my permissions? Should nginx (and/or apache) be able to access folders in /Users/user/..?

like image 924
colmjude Avatar asked Oct 16 '25 11:10

colmjude


2 Answers

Add user username staff; to nginx.conf. That worked for me. Not sure it is good for security.

like image 182
vvkatwss vvkatwss Avatar answered Oct 18 '25 21:10

vvkatwss vvkatwss


I just want to add some details

nginx.conf path is here:

/usr/local/etc/nginx/nginx.conf

we should edit it and in line 3 add this line: user username staff; and username is your username for example:

user alex.sa staff;

and after that:

sudo service nginx reload

or

sudo systemctl reload nginx

to restart the Nginx

and after that it will work

My configuration is in this path: /usr/local/etc/nginx/servers/myExample.test.conf

Note:

You can test your Nginx configuration syntax with

sudo nginx -t
like image 36
Raskul Avatar answered Oct 18 '25 23:10

Raskul