Nginx出现403 forbidden(Permission denied)报错的四种方法

 

 

 

 

查看nginx的error.log日志。打开日志出现Permission denied:

1.启动用户和nginx的工作用户不一致所致

查看nginx的启动用户,发现是www,而为是用root启动的
ps aux | grep "nginx: worker process" | awk '{print $1}'
www
www
... root

2将nginx.conf的user用户改为和启动用户一样

3.缺少index.html或者index.php文件,就是配置文件中index index.html index.htm这行中的指定的文件

如果在/home/wwwroot/xamsjb.com/public下面没有index.php,index.html的时候,直接文件,会报403 forbidden

 4.权限问题

修改/home/wwwroot/xamsjb.com/public权限问题,改为目录的所属用户,重启nginx即可。

chmod -R 777 /home/wwwroot/xamsjb.com/public

5.修改SELinux的配置为关闭状态。

临时关闭:setenforce 0

永久关闭:vi /etc/selinux/config,SELINUX=enforcing改为SELINUX=disabled

 

posted @ 2018-06-17 18:47  风中驻足  阅读(3202)  评论(0编辑  收藏  举报