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目录的权限

相关推荐

  1. NGINX location用法

    2024-07-18 17:18:04       56 阅读
  2. 解析Nginx配置文件conf中常用

    2024-07-18 17:18:04       52 阅读
  3. Nginx高可用实施指南:从规划到部署全面解析

    2024-07-18 17:18:04       39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-18 17:18:04       70 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-18 17:18:04       74 阅读
  3. 在Django里面运行非项目文件

    2024-07-18 17:18:04       62 阅读
  4. Python语言-面向对象

    2024-07-18 17:18:04       72 阅读

热门阅读

  1. opencv—常用函数学习_“干货“_6

    2024-07-18 17:18:04       20 阅读
  2. web前端 Vue 框架面试120题(四)

    2024-07-18 17:18:04       20 阅读
  3. 富格林:可信办法阻挠虚假受骗

    2024-07-18 17:18:04       20 阅读
  4. ClickHouse中使用UNION

    2024-07-18 17:18:04       21 阅读
  5. vue3项目中pinia的用法详解(值得收藏)

    2024-07-18 17:18:04       21 阅读
  6. jd-gui反编译出现中文乱码问题

    2024-07-18 17:18:04       19 阅读
  7. CL11命令行解析使用实例

    2024-07-18 17:18:04       20 阅读
  8. PCB的层叠结构

    2024-07-18 17:18:04       19 阅读
  9. vim+cscope+ctags

    2024-07-18 17:18:04       24 阅读
  10. gitlab reset passwd

    2024-07-18 17:18:04       22 阅读
  11. 02-Redis未授权访问漏洞

    2024-07-18 17:18:04       23 阅读
  12. 开发一个商城app需要多少钱

    2024-07-18 17:18:04       23 阅读
  13. 【STM32】超声波一般常用哪两个引脚?

    2024-07-18 17:18:04       20 阅读
  14. Linux 之 ln 硬链接和软链接

    2024-07-18 17:18:04       21 阅读