Nginx 403 Forbidden 问题

今天在一个新的环境上安装Nginx,结果访问的都是403

full

通常显示403我立马都会想到路径配置不对,但我仔细看了一下,目录路径没问题

nginx.conf

server {
  listen       80;
  server_name  localhost;

  #charset koi8-r;

  #access_log  logs/host.access.log  main;

  location / {
    root   /root/html;
    index  index.html index.htm;
  }
}

系统中的路径查询结果正常

[root@lizhong html]# ll /root/html/
总用量 4
-rw-r--r-- 1 root root 3 4月  18 11:07 index.html

目录存在,重启Nginx还是这个错误,后来想到是不是权限问题?于是在nginx.conf头部加入一行:

user  root;

重启nginx再访问,就可以正常访问了,如果不想使用root用户运行,可以通过修改目录访问权限解决403问题,但不能把目录放在root用户宿主目录下,放在任意一个位置并给它755,或者通过chown改变它的拥有者与Nginx运行身份一致也可以解决权限问题。

分享

TITLE: Nginx 403 Forbidden 问题

LINK: https://www.qttc.net/432-nginx-403-forbidden.html

NOTE: 原创内容,转载请注明出自琼台博客