nginx配置文件里user只能是root,否则报403错误

yum 一个全新的nginx,版本是1.12.2的
 
直接启动,浏览器输入localhost访问的nginx页面
 
1、当我将nginx.conf配置文件里root 路径改成/root/html/index.html
 
#mkdir /root/html
#echo hello > /root/html/index.html
(不用改访问目录权限。不放心对照原始成功的/usr/share/nginx/html/index.html的路径权限)
报错:
root@localhost nginx]# curl localhost
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.12.2</center>
</body>
</html>
查看错误日志:
[root@localhost nginx]# tail -n30 error.log 
2018/01/30 01:35:57 [error] 3511#0: *1 "/root/html/index.html" is forbidden (13: Permission denied), client: ::1, server: _, request: "GET / HTTP/1.1", host: "localhost"
2018/01/30 01:36:50 [error] 3567#0: *1 "/root/html/index.html" is forbidden (13: Permission denied), client: ::1, server: _, request: "GET / HTTP/1.1", host: "localhost"
2018/01/30 01:37:20 [error] 3640#0: *1 "/root/html/index.html" is forbidden (13: Permission denied), client: ::1, server: _, request: "GET / HTTP/1.1", host: "localhost"
2018/01/30 01:38:40 [error] 3640#0: *2 "/root/html/index.html" is forbidden (13: Permission denied), client: ::1, server: _, request: "GET / HTTP/1.1", host: "localhost"
2018/01/30 01:40:27 [error] 3878#0: *2 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: ::1, server: _, request: "GET /favicon.ico HTTP/1.1", host: "localhost"
2018/01/30 01:40:27 [error] 3878#0: *2 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: ::1, server: _, request: "GET /favicon.ico HTTP/1.1", host: "localhost"
2018/01/30 01:50:58 [error] 4590#0: *1 "/root/html/index.html" is forbidden (13: Permission denied), client: ::1, server: _, request: "GET / HTTP/1.1", host: "localhost"
 
 
2、再改,将nginx.conf里的user nginx改成
user root;
成功:
[root@localhost ~]# curl localhost
hello
3、不行,我不要将user 变成root,改回来:
user nginx;
 
重启后,报403的错误。
 
 
参考解答:https://stackoverflow.com/questions/31729212/nginx-root-index-html-forbidden-13-permission-denied
 
4、将访问目录换出root
      我改成了/data/html/index.html
 okokokoko
 
 
总结:用户和访问路径不符合。
指定root用户 -----访问路径随便
其他用户(nginx,www)----->访问路径就不可以在/root下
 
 
ps:nginx的有些配置web访问配置为什么只能写在主配置文件里,扩展配置文件和主配置文件有什么区别呢???
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Nginx 配置文件是一个文本文件,通常位于 `/etc/nginx/` 目录下,主要包括以下几个部分: 1. 全局块:配置影响 nginx 全局的指令,一般有运行 nginx用户组、nginx 进程 pid 存放路径、日志存放路径和类型以及配置文件引入等。 2. events 块: 配置影响 nginx 服务器或与用户的网络连接,常用于设置连接超时时间、最大连接数等。 3. http 块:http 块中定义的配置指令用于处理 Web 请求,主要包括了 MIME 类型、字符集、缓存、请求限制等。 4. server 块:配置虚拟主机的相关参数,一个 http 块中可以包含多个 server 块,每个 server 块就相当于一个虚拟主机,用于处理来自客户端的请求。 一个简单的 Nginx 配置文件示例如下: ``` user nginx; worker_processes auto; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; server { listen 80; server_name example.com; location / { root /usr/share/nginx/html; index index.html index.htm; } } } ``` 这个配置文件包含全局块和一个 server 块,其中: - `user` 指定 Nginx 运行的用户; - `worker_processes` 指定 Nginx 启动的 worker 进程数; - `error_log` 指定错误日志文件路径和级别; - `pid` 指定 Nginx 进程 ID 存放路径; - `events` 块中 `worker_connections` 指定每个 worker 进程最大连接数; - `http` 块中 `include` 指定 MIME 类型配置文件路径; - `default_type` 指定默认 MIME 类型; - `access_log` 指定访问日志文件路径和格式; - `sendfile` 指定是否使用 sendfile 函数传输文件; - `keepalive_timeout` 指定 keep-alive 连接超时时间; - `server` 块中 `listen` 指定监听端口和协议; - `server_name` 指定虚拟主机域名; - `location` 指定请求 URL 和对应的文件路径。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值