Nginx 403 Forbidden 解決方案 史上最靠譜

緣由 1. SELinux爲開啓狀態(enabled)

  1. 查看SELinux的狀態
sestatus

  若是不是 disables , 須要php

vi /etc/selinux/config

  將之前的 SELINUX=enforcing 改成 SELINUX=disabled ,以下所示html

# 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 two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

  保存後,reboot重啓系統便可。linux

注:這是個大坑!!!至於SELinux是什麼請自行百度:)nginx

 

緣由 2. 權限問題

  例如網站根目錄爲 /var/www/html/    , 首頁文件爲 /var/www/html/index.htmlbash

  除了index.html文件根據需求設置權限,例如網站

chmod 644 /var/www/html/index.html

  必須將這個文件所在的目錄設置爲有 讀 和 操做 的權限spa

chmod -R 755 /var/www/html

 

注: 這個沒多大亂用,幾乎全部的文件(夾)都符合須要的權限。code

 

緣由 3. 沒有指定的文件index.html等

  這個就不詳細舉例了,細心點不會在這裏犯錯的,htm

  在nginx配置文件裏按須要寫上主頁名,別忘了後面的分號就行。blog

index  index.php index.html;  

 

 

 

------------------------PS--------------------------

 

 

這個問題沒把我急死,文件權限修改了無數次怎麼也不行,終於發現是SELinux的鍋,既然暫時用不到這個東東,就將它禁用~~~

或許更改用戶組權限也能夠解決這個問題,留待心情好了再看看~

 

 

________________END________________

相關文章
相關標籤/搜索