nginx 403 Forbidden错误的原因和解决方法

问题总是等着自己去解决,刚弄了下nginx开机自启动和开机禁用防火墙,可是在浏览器访问却报了403 Forbidden错误。

查看错误日志,发现是权限不足导致的。

[root@localhost logs]# cat error.log 
2018/04/13 08:54:50 [emerg] 1179#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/04/13 08:54:50 [emerg] 1179#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/04/13 08:54:50 [emerg] 1179#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/04/13 08:54:50 [emerg] 1179#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/04/13 08:54:50 [emerg] 1179#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/04/13 08:54:50 [emerg] 1179#0: still could not bind()
2018/04/13 08:55:03 [notice] 1180#0: signal process started
2018/04/13 10:02:45 [error] 918#0: *1 "/root/hbk/nginx2//html/index.html" is forbidden (13: Permission denied), client:uest: "GET / HTTP/1.1", host: "192.168.254.128"
2018/04/13 10:02:45 [error] 918#0: *1 open() "/root/hbk/nginx2//html/favicon.ico" failed (13: Permission denied), clienequest: "GET /favicon.ico HTTP/1.1", host: "192.168.254.128", referrer: "http://192.168.254.128/"
2018/04/13 10:02:52 [error] 918#0: *1 "/root/hbk/nginx2//html/index.html" is forbidden (13: Permission denied), client:uest: "GET / HTTP/1.1", host: "192.168.254.128"
2018/04/13 10:02:52 [error] 918#0: *1 open() "/root/hbk/nginx2//html/favicon.ico" failed (13: Permission denied), clienequest: "GET /favicon.ico HTTP/1.1", host: "192.168.254.128", referrer: "http://192.168.254.128/"
2018/04/13 10:03:05 [error] 918#0: *1 "/root/hbk/nginx2//html/index.html" is forbidden (13: Permission denied), client:uest: "GET / HTTP/1.1", host: "192.168.254.128"

网上看了相关几篇博客,才知道是因为配置文件conf/nginx.conf文件的执行用户和当前用户不一致导致的,把之前的nobody改成当前用户root。

user root;
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

重启配置即可,问题完美解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄宝康

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值