2

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/..?

colmjude
  • 194
  • 1
  • 8

2 Answers2

4

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

vvkatwss vvkatwss
  • 3,345
  • 1
  • 21
  • 24
0

thanks to 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 the line 3 add this line: user username staff; and username is your username for example:

user alex.sa staff;

and after that:

sudo nginx -s stop
sudo nginx

to restart the nginx

and after that it will work

my configuration in /usr/local/etc/nginx/servers/myExample.test.conf is

Raskul
  • 1,674
  • 10
  • 26