Nginx全局块的user指令

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指令可以指定启动运行工作进程的用户及用户组,这样对于系统的权限访问控制的更加精细,也更加安全。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nginx全局变量配置详解如下: 在nginx的配置文件中,可以使用全局变量来实现一些配置的判断和处理。全局变量在整个nginx配置中都是可见的,可以在不同的上下文中使用。 在引用中的示例中,主要使用了两个全局变量:$host和$request_uri。$host表示当前请求的主机名,$request_uri表示当前请求的URI。通过这些全局变量的值,可以进行条件判断和重定向跳转等操作。 另外,在nginx的配置中,还可以使用其他一些全局变量,例如: - $remote_addr:客户端的IP地址 - $http_user_agent:客户端的User-Agent信息 - $http_referer:客户端的Referer信息 $args:查询参数部分 - $scheme:请求的协议(http或https) 除了使用这些内置的全局变量外,还可以通过自定义变量来扩展nginx的功能。可以使用set指令来定义变量,并在配置中使用。 在nginx全局配置中,可以使用全局、events和http来进行配置。全局中的配置影响全局,包括运行nginx的用户组、进程存放、日志、配置文件等。events用于配置nginx服务器与客户端的网络连接,包括进程最大连接数、数据驱动模型、序列化等。http是最常用的配置,用于配置代理、缓存、日志和第三方模等。 在http中,可以嵌套多个server,每个server表示一个虚拟主机的参数配置。而在server中,可以使用location来配置请求路由和页面处理。 综上所述,nginx全局变量配置详解如上所述,主要包括内置的全局变量和自定义变量的使用,以及全局、events和http的配置结构。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Nginx 配置详解](https://blog.csdn.net/u011262253/article/details/120941175)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值