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/..?
Add user username staff; to nginx.conf. That worked for me. Not sure it is good for security.
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
You can test your Nginx configuration syntax with
sudo nginx -t
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With