1. 程式人生 > 其它 >第二十四章 Nginx 403 Forbidden 報錯解決

第二十四章 Nginx 403 Forbidden 報錯解決

對於運維來說,Nginx 報錯: 403 forbidden,首先會想到許可權問題,如果許可權沒有問題,那還有什麼錯誤會報403 forbidden呢?

一、許可權問題

三步走:

#1.檢查nginx.conf的user 是否為root;

#2.檢查檔案所屬目錄是否有許可權

#3.檢查nginx程式目錄許可權

二、Selinux沒關(最為意想不到)

今天部署生產環境,發現一直報錯:403 forbidden
最後檢視selinux發現selinux狀態為:
[root@mccann-dbh /data]$ getenforce 
enforcing

修改selinux狀態:
# 臨時修改
[root@mccann-dbh /data]$ setenforce 0

[root@mccann-dbh /data]$ getenforce 
permissive

#永久修改
[root@mccann-dbh /data]$ vim /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

過載nginx,發現可以正常訪問了。

三、缺少索引檔案

#1.缺少index.html檔案
server { 
listen    80; 
server_name http://dbhh5.mccann.dataxbusiness.com/; 
index index.html; 
root /data/webproject/dbhh5; 

如果在/data/webproject/dbhh5下面沒有index.php,index.html的時候,直接訪問域名,找不到檔案,會報403 forbidden。