您的位置:首页 > 运维架构 > Nginx

Nginx:修改配置文件中的user解决访问资源文件时返回403 premission denied

2017-06-15 16:19 639 查看
在nginx配置一个页面,配置代码如下:

server {
listen 8000;
server_name api.demo.com;

root /Users/KK/demo
index index.html index.htm index.nginx-debian.html;

location / {
proxy_pass http://localhost:8081; }
location ~* \.(js|jpg|png|css)$ {
root /Users/KK/demo/public
}


意思是如果是html则转发到8081端口上处理,如果是js、css、图片等资源文件,则直接由nginx访问并返回。发现取回的内容格式不正确,所有资源文件都没有取到。查看访问日志找到这样的内容:

2017/06/15 11:25:20 [error] 27879#636763: *284 open() "/Users/KK/demo/public/images/user.png" failed (13: Permission denied), client: 127.0.0.1, server: api.demo.com, request: "GET /images/user.png HTTP/1.1", host: "api.demo.com:8000"


使用命令行查看nginx运行情况:

kk:~ KK$ ps aux |grep nginx
nobody          27879   0.0  0.0  2509100    672   ??  S    11:23上午   0:00.01 nginx: worker process
nobody          27878   0.0  0.0  2509492    740   ??  S    11:23上午   0:00.47 nginx: worker process
nobody          27877   0.0  0.0  2509492    740   ??  S    11:23上午   0:00.48 nginx: worker process
nobody          27876   0.0  0.0  2509492    740   ??  S    11:23上午   0:00.48 nginx: worker process
root            27558   0.0  0.0  2509748    892   ??  Ss   10:25上午   0:00.08 nginx: master process openresty
KK              27935   0.0  0.0  2450212   1980 s002  S+    2:58下午   0:00.00 grep nginx


说明主进程是由root调用,worker进程由nobody调用,这是因为配置中没有指定用户。

#nginx.conf
user kk www;
worker_processes  auto;
pid /usr/local/var/run/openresty.pid;


user
后的两个参数分别是用户名和用户组。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx