当前位置: 首页 > news >正文

nginx全局块的user指令

文章目录

  • 1、user指令
    • 1.1、进入nginx解压的目录
    • 1.2、./configure --help
    • 1.3、工作进程默认是nobody
  • 2、user指令的使用步骤:
    • 2.1、设置一个用户信息"www"
    • 2.2、 创建一个用户
    • 2.3、./nginx -s reload
    • 2.4、创建/root/html/index.html页面,添加如下内容
    • 2.5、修改nginx.conf
    • 2.6、测试启动访问
    • 2.7、分析原因

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 forworker processes--group=GROUP                      set non-privileged group forworker 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目录的权限

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 基于 Vue 3 和 Element Plus 构建图书管理系统
  • 计算机毕业设计Python深度学习游戏推荐系统 Django PySpark游戏可视化 游戏数据分析 游戏爬虫 Scrapy 机器学习 人工智能 大数据毕设
  • Airdrop 2049 第二季如何捕捉全新机遇?专家大咖带你揭秘!
  • B树:深入解析与实战应用
  • 华为的热机备份和流量限制
  • 纯净IP的判断标准及代理深度分析
  • Unity3d开发google chrome的dinosaur游戏
  • 数据可视化入门
  • 【CPO-TCN-BiGRU-Attention回归预测】基于冠豪猪算法CPO优化时间卷积双向门控循环单元融合注意力机制
  • https 单向认证和双向认证
  • Postfix+Dovecot+Roundcube开源邮件系统搭建系列1-2:系统搭建目标+MariaDB数据库配置(MySQL)
  • 网络规划设计师教程(第二版) pdf
  • 数据库系统概论:数据库完整性
  • Pytorch:显卡驱动版本、Pytorch版本的关系
  • vue中:class、watch、v-show使用
  • 4个实用的微服务测试策略
  • 77. Combinations
  • AngularJS指令开发(1)——参数详解
  • log4j2输出到kafka
  • Quartz初级教程
  • VuePress 静态网站生成
  • Vue--数据传输
  • 阿里云购买磁盘后挂载
  • 笨办法学C 练习34:动态数组
  • 当SetTimeout遇到了字符串
  • 给第三方使用接口的 URL 签名实现
  • 海量大数据大屏分析展示一步到位:DataWorks数据服务+MaxCompute Lightning对接DataV最佳实践...
  • 利用DataURL技术在网页上显示图片
  • 浏览器缓存机制分析
  • 前端 CSS : 5# 纯 CSS 实现24小时超市
  • 如何设计一个微型分布式架构?
  • 怎样选择前端框架
  • LevelDB 入门 —— 全面了解 LevelDB 的功能特性
  • 策略 : 一文教你成为人工智能(AI)领域专家
  • ​LeetCode解法汇总2670. 找出不同元素数目差数组
  • ​必胜客礼品卡回收多少钱,回收平台哪家好
  • ​如何使用QGIS制作三维建筑
  • !! 2.对十份论文和报告中的关于OpenCV和Android NDK开发的总结
  • "无招胜有招"nbsp;史上最全的互…
  • $redis-setphp_redis Set命令,php操作Redis Set函数介绍
  • (C语言)输入自定义个数的整数,打印出最大值和最小值
  • (day6) 319. 灯泡开关
  • (M)unity2D敌人的创建、人物属性设置,遇敌掉血
  • (顶刊)一个基于分类代理模型的超多目标优化算法
  • (蓝桥杯每日一题)平方末尾及补充(常用的字符串函数功能)
  • (六)软件测试分工
  • (转)eclipse内存溢出设置 -Xms212m -Xmx804m -XX:PermSize=250M -XX:MaxPermSize=356m
  • (转)Mysql的优化设置
  • (转)负载均衡,回话保持,cookie
  • (转)可以带来幸福的一本书
  • (转)一些感悟
  • .bat文件调用java类的main方法
  • .NET 5种线程安全集合
  • .NET BackgroundWorker
  • .NET CF命令行调试器MDbg入门(二) 设备模拟器