nginx 403 Forbidden錯誤的原因和解決方法
阿新 • • 發佈:2019-01-10
問題總是等著自己去解決,剛弄了下nginx開機自啟動和開機禁用防火牆,可是在瀏覽器訪問卻報了403 Forbidden錯誤。
檢視錯誤日誌,發現是許可權不足導致的。
[[email protected] 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;
}
重啟配置即可,問題完美解決。