优化网站安全性:nginx全局块的user指令实用技巧
AI 概述
1. user 指令1.1 进入 nginx 解压的1.2 ./configure –help1.3 工作进程默认是 nobody2. user 指令的使用步骤2.1 设置一个用户信息”www”2.2 创建一个用户2.3 ./nginx -s reload2.4 创建/root/html/index.html 页面2.5 修改 nginx.conf2.6 测试启动访问
本文主要介绍 nginx 全局块...
目录
文章目录隐藏
本文主要介绍 nginx 全局块的 user 指令的实现示例,该指令用于配置运行 Nginx 服务器的 worker 进程的用户和用户组。以下是使用示例,可供大家参考,建议了解一下。
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 rel="nofollow" href="https://mybj123.com/links?url=aHR0cDovL215YmoxMjMuY29tLw==" rel="external nofollow" >码云笔记</a>.
<p><em>Thank you for using mybj123.</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 拒绝访问的错误:

以上就是关于 nginx 全局块的 user 指令的使用示例的全部内容,更多内容请关注码云笔记其它相关文章!
以上关于优化网站安全性:nginx全局块的user指令实用技巧的文章就介绍到这了,更多相关内容请搜索码云笔记以前的文章或继续浏览下面的相关文章,希望大家以后多多支持码云笔记。
声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请将相关资料发送至 admin@mybj123.com 进行投诉反馈,一经查实,立即处理!
重要:如软件存在付费、会员、充值等,均属软件开发者或所属公司行为,与本站无关,网友需自行判断
码云笔记 » 优化网站安全性:nginx全局块的user指令实用技巧
如若内容造成侵权/违法违规/事实不符,请将相关资料发送至 admin@mybj123.com 进行投诉反馈,一经查实,立即处理!
重要:如软件存在付费、会员、充值等,均属软件开发者或所属公司行为,与本站无关,网友需自行判断
码云笔记 » 优化网站安全性:nginx全局块的user指令实用技巧

微信
支付宝