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;
}

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

你可能感兴趣的:(nginx)