i've just installed nginx on an Archlinux box and encounter this problem:
Nginx is configured to run as "nginx", a new user/group that I added, in /etc/nginx/nginx.conf
:
user nginx nginx;
For doublecheck:
$ ps aux | grep nginx
nginx 9678 0.0 0.5 28472 2856 ? S 17:37 0:00 nginx: worker process
nginx 9679 0.0 0.5 28472 2856 ? S 17:37 0:00 nginx: worker process
root 31912 0.0 0.6 28084 3364 ? Ss 17:24 0:00 nginx: master process /usr/bin/nginx -g pid /run/nginx.pid; error_log stderr;
The root of the server is at:
location / {
root /home/lamnk/sites/host.com;
index index.html index.htm;
}
and the owner of the file is set to nginx too:
$ ls -la /home/lamnk/sites/host.com
total 12
drwxr-xr-x 2 lamnk http 4096 Jan 12 09:37 .
drwxr-xr-x 3 lamnk users 4096 Jan 12 09:36 ..
-rw-r--r-- 1 nginx nginx 21 Jan 12 09:37 index.html
When I go to host.com
, I got the 403 forbidden error. In the error.log
:
2016/01/12 17:28:23 [error] 31914#0: *2 open() "/home/lamnk/sites/host.com/index.html" failed (13: Permission denied), client: 171.233.242.40, server: host.com, request: "GET /index.html HTTP/1.1", host: "host.com"
But when I change nginx to run as my own username lamnk
, then nginx can return the content correctly, without any other changes in file permission. What gives??
EDIT: the permissions on parent directories:
$ namei -l /home/lamnk/sites/host.com
f: /home/lamnk/sites/host.com
drwxr-xr-x root root /
drwxr-xr-x root root home
drwx------ lamnk users lamnk
drwxr-xr-x lamnk users sites
drwxr-xr-x lamnk http host.com