user指令
(1)user:用于配置运行Nginx服务器的worker进程的用户和用户组。
语法 | user user [group] |
---|---|
默认值 | nobody |
位置 | 全局块 |
该属性也可以在编译的时候指定,语法如下./configure --user=user --group=group
,如果两个地方都进行了设置,最终生效的是配置文件中的配置。
该指令的使用步骤:
(1)设置一个用户信息"www"
user www;
(2) 创建一个用户
useradd www
(3)修改user属性
user www
(4)创建/root/html/index.html
页面,添加如下内容
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</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>
(5)修改nginx.conf
location / {
root /root/html;
index index.html index.htm;
}
(5)测试启动访问
页面会报403拒绝访问的错误
(6)分析原因
因为当前用户没有访问/root/html目录的权限
(7)将文件创建到 /home/www/html/index.html
,修改配置
location / {
root /home/www/html;
index index.html index.htm;
}
(8)再次测试启动访问
能正常访问。
综上所述,使用user指令可以指定启动运行工作进程的用户及用户组,这样对于系统的权限访问控制的更加精细,也更加安全。