nginx全局块的user指令

1、user指令

user:用于配置运行Nginx服务器的 worker进程 的用户和用户组。

语法user user[group]
默认值nobody
位置全局块

该属性也可以在编译的时候指定,语法如下:

./configure --user=user
./configure --group=group

如果两个地方都进行了设置,最终生效的是配置文件中的配置。

1.1、进入nginx解压的目录

[root@localhost conf]# cd /opt/tool/nginx/nginx-1.20.1/
[root@localhost nginx-1.20.1]# pwd
/opt/tool/nginx/nginx-1.20.1

1.2、./configure --help

[root@localhost nginx-1.20.1]# ./configure --help
  --user=USER                        set non-privileged user for
                                     worker processes
  --group=GROUP                      set non-privileged group for
                                     worker processes

1.3、工作进程默认是nobody

[root@localhost nginx-1.20.1]# ps -ef | grep nginx
root       7337      1  0 18:12 ?        00:00:00 nginx: master process ./nginx
nobody     7338   7337  0 18:12 ?        00:00:00 nginx: worker process
root       7719   7193  0 18:48 pts/0    00:00:00 grep --color=auto nginx
[root@localhost nginx-1.20.1]# cat /usr/local/nginx/conf/nginx.conf

#user  nobody;

2、user指令的使用步骤:

2.1、设置一个用户信息"www"

修改nginx.conf配置文件中的#user nobody;为user www;
在这里插入图片描述

user www;
[root@localhost sbin]# pwd
/usr/local/nginx/sbin
[root@localhost sbin]# ./nginx -t
nginx: [emerg] getpwnam("www") failed in /usr/local/nginx/conf/nginx.conf:2
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

发现配置文件测试失败,这个时候我们需要创建一个用户www

2.2、 创建一个用户

[root@localhost sbin]# useradd www
[root@localhost sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost sbin]# ps -ef | grep nginx
root       7337      1  0 18:12 ?        00:00:00 nginx: master process ./nginx
nobody     7338   7337  0 18:12 ?        00:00:00 nginx: worker process
root       8006   7193  0 19:12 pts/0    00:00:00 grep --color=auto nginx

2.3、./nginx -s reload

[root@localhost sbin]# ./nginx -s reload
[root@localhost sbin]# ps -ef | grep nginx
root       7337      1  0 18:12 ?        00:00:00 nginx: master process ./nginx
www        8016   7337  0 19:13 ?        00:00:00 nginx: worker process
root       8018   7193  0 19:13 pts/0    00:00:00 grep --color=auto nginx

2.4、创建/root/html/index.html页面,添加如下内容

[root@localhost sbin]# cd /root/
[root@localhost ~]# mkdir html
[root@localhost ~]# cd html/
[root@localhost html]# vim index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans^Bserif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is
successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer
to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
<p><em>I am WWW</em></p>
</body>
</html>

在这里插入图片描述

file:///usr/local/nginx/html/index.html

2.5、修改nginx.conf

location / {
root /root/html;
index index.html index.htm;
}
[root@localhost conf]# pwd
/usr/local/nginx/conf
[root@localhost conf]# vim nginx.conf
[root@localhost conf]# cd ../sbin/
[root@localhost sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost sbin]# ./nginx -s reload

2.6、测试启动访问

页面会报403拒绝访问的错误
在这里插入图片描述

2.7、分析原因

因为当前用户没有访问/root/html目录的权限

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值