解决Nginx出现403 forbidden (13: Permission denied)报错的四种

我是在在本地用虚拟机中通过yum安装nginx的,安装一切正常,但是访问时报403,

于是查看nginx日志,路径为/var/log/nginx/error.log。打开日志发现报错Permission denied,详细报错如下:

 

2018/11/28 11:39:40 [error] 41772#41772: *130 "/home/hc/dists/autoAweme/dist/index.html" is forbidden (13: Permission denied), client: 192.168.3.139, server: 192.168.3.139, request: "GET / HTTP/1.1", host: "192.168.3.139"

原因一:由于启动用户和nginx工作用户不一致所致

1 查看nginx的启动用户

命令:

 

ps aux | grep "nginx: worker process" | awk '{print $1}'

 

[root@localhost hc]# ps aux | grep "nginx: worker process" | awk '{print $1}' nginx root

发现是nginx,而不是用root启动的

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

将nginx.conf文件中的 user 对应的nginx 改为 root ,改完后重启

 

[root@localhost hc]# vim /etc/nginx/nginx.conf [root@localhost hc]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@localhost hc]# nginx -s reload

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

 

server { listen 80; server_name localhost; index index.php index.html; root / var/www; }

如果在/ var/www下面没有index.php,index.html的时候,直接访问域名,找不到文件,会报403 forbidden。

三、权限问题,如果nginx没有web目录的操作权限,也会出现403错误。

解决办法:修改web目录的读写权限,或者是把nginx的启动用户改成目录的所属用户,重启Nginx即可解决

 

chmod -R 755 / var/www

四、SELinux设置为开启状态(enabled)的原因

首先查看本机SELinux的开启状态,如果SELinux status参数为enabled即为开启状态

 

/usr/sbin/ sestatus -v

或者使用getenforce命令检查

如何关闭 SELinux 呢

1.临时关闭(不用重启)

 

setenforce 0

2. 永久关闭(需要重启)

修改配置文件 /etc/ selinux/config,将SELINUX=enforcing改为SELINUX=disabled

 

vi /etc/selinux/config #SELINUX=enforcing SELINUX=disabled

重启生效。

 

reboot

参考:https://blog.csdn.net/onlysunnyboy/article/details/75270533

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值