第二十四章 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。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM