Nginx全局块的user指令

​ 首先把配置文件的/usr/local/nginx/conf/nginx.conf中的第一句改成user nobody —>user www。再在sbin目录下检查配置。

没有www用户

​ 就要添加www用户,然后重启nginx看看worker进程的用户是否改变。

worker进程的改变

问题描述

前提条件当nginx.conf的 usr设置成 user www; 时

nginx.conf的配置路径 访问效果
在nginx.conf中写root html【其实是/usr/local/nginx/html/】
在nginx.conf中写root /root/html ×
在nginx.conf中写root /home/www/html

​ 在配置文件中root后面的html是代表/usr/local/nginx/html/index.html路径下成功访问。

nginx配置原始

image-20220325221139705若写成root /root/html/index.html就会报错,先在nginx的sbin验证配置然后再然后重启,发现配置没问题重启也没有问题就是访问不了。

image-20220325231646232

nginx访问失败

问题解决

​ 执行su www进入/home/www/目录,再把/usr/local/nginx/html/文件夹复制到此目录。重新修改nginx.conf中的root路径写成 root /home/www/html重启就好了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[root@localhost www]# su www
[www@localhost ~]$ cp -r /usr/local/nginx/html/ ./
[www@localhost ~]$ ll
总用量 12
-rw-r--r--. 1 www www 589 3月 25 23:39 50x.html
-rw-r--r--. 1 www www 131 3月 25 23:39 haha.html
-rw-r--r--. 1 www www 676 3月 25 23:39 index.html
[www@localhost html]$ vim index.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 zhoududd</em></p>
<p><em>Nice to meet you for www lujing </em></p>// 这里修改了和原始文件做区分
</body>
</html>

www用户的配置

www用户访问成功

总结

​ 配置文件nginx.conf中user要和root对应才行。

nginx.conf的user和root的对应关系