解決SELinux對網站目錄許可權控制的不當的問題
前言:本文主要介紹了因為SELinux對網站目錄許可權控制的不當而引起網站無法正常操作和訪問的問題。
正文開始:今天下午閒著沒有事做於是突然興起想嘗試安裝下Drupal。以前用Wordpress做部落格久了,總想著嚐嚐新。
按照Installtion Guide提示的安裝步驟進行操作如下:
- wget http://drupal.org/files/projects/drupal-7.12.tar.gz
- tar -zxvf drupal-7.12.tar.gz
- mv drupal-7.12 /var/www/html/home_start
- cd /var/www/html/home_start
- cp sites/default/default.settings.php sites/default/settings.php
- chmod a+w sites/default/settings.php
- chmod a+w sites/default
- mysqladmin -u username -p create databasename #用正確的字串代替username和databasename
一切準備就緒!就等著進網站目錄進行下一步配置了!
不幸的是,在瀏覽器中開啟網站的目錄後就遭遇了httpd的403拒絕訪問提示。
這很顯然,根據以往的經驗可以判斷是目錄許可權存在問題。
為了驗證這一說法,我們可以檢查httpd的錯誤日誌。預設情況下日誌就存在在/var/log/httpd/目錄中。
- [root@localhost ~]# grep Permission /var/log/httpd/error_log
- [Tue Apr 10 09:07:04 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /start denied
- [Tue Apr 10 09:07:50 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /start/ denied
- [Tue Apr 10 09:08:07 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /start/ denied
- [Tue Apr 10 09:10:06 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /start/ denied
- [Tue Apr 10 09:11:08 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /start/ denied
- [Tue Apr 10 09:11:17 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /start denied
- [Tue Apr 10 09:11:34 2012] [error] [client ::1] (13)Permission denied: access to /start denied
- [Tue Apr 10 09:13:35 2012] [error] [client ::1] (13)Permission denied: access to /start denied
- [Tue Apr 10 09:13:51 2012] [error] [client ::1] (13)Permission denied: access to /start/site/default/ denied
- [Tue Apr 10 09:13:57 2012] [error] [client ::1] (13)Permission denied: access to /start/sites denied
- [Tue Apr 10 09:14:51 2012] [error] [client ::1] (13)Permission denied: access to /start/install.php denied
- [Tue Apr 10 09:18:57 2012] [error] [client ::1] (13)Permission denied: access to /start/install.php denied
- [Tue Apr 10 09:19:01 2012] [error] [client ::1] (13)Permission denied: access to /start/ denied
- [Tue Apr 10 09:22:03 2012] [error] [client ::1] (13)Permission denied: access to /start denied
- [Tue Apr 10 09:22:21 2012] [error] [client ::1] (13)Permission denied: access to /start denied
- [Tue Apr 10 09:22:24 2012] [error] [client ::1] (13)Permission denied: access to /start denied
- [Tue Apr 10 09:22:27 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /start denied
- [Tue Apr 10 09:27:02 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /start denied
- [Tue Apr 10 09:27:05 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /start denied
- [Tue Apr 10 09:27:07 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /start denied
- [Tue Apr 10 12:09:58 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /home_start denied
- [Tue Apr 10 12:42:38 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /home_start denied
- [Tue Apr 10 12:42:40 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /home_start denied
- [Tue Apr 10 12:44:15 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /home_start denied
- [Tue Apr 10 12:44:20 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /home_start denied
- [Tue Apr 10 20:53:21 2012] [error] [client ::1] (13)Permission denied: access to /home_start denied
- [Tue Apr 10 21:07:21 2012] [error] [client ::1] (13)Permission denied: access to /home_start denied
- [Tue Apr 10 21:14:48 2012] [error] [client ::1] (13)Permission denied: access to /home_start denied
- [root@localhost ~]#
再檢查網站目錄和檔案的許可權。為方便起見直接用-lZ選項。用於顯示詳細資訊和SELinux許可權資訊
- [root@localhost html]# ls -lZ
- -rw-r–r–. root root unconfined_u:object_r:httpd_sys_content_t:s0 archive.html
- drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 blog
- drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 blog_backup
- -rw-r–r–. root root unconfined_u:object_r:httpd_sys_content_t:s0 blog.htm
- -rw-r–r–. root root unconfined_u:object_r:httpd_sys_content_t:s0 blog.html
- drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 css
- drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 home_page
- drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 home_start #問題行
- drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 images
- -rw-r–r–. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.htm
- -rw-r–r–. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
- -rw-r–r–. root root unconfined_u:object_r:httpd_sys_content_t:s0 info_php.php
- drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 js
- -rw-r–r–. root root unconfined_u:object_r:httpd_sys_content_t:s0 log
- drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 php #以前的遺留問題
- drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 phpMyAdmin-3.4.10.1-all-languages
- drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 PSDs
- -rw-r–r–. root root unconfined_u:object_r:httpd_sys_content_t:s0 readme.txt
- -rw-r–r–. root root unconfined_u:object_r:httpd_sys_content_t:s0 style.htm
- -rw-r–r–. root root unconfined_u:object_r:httpd_sys_content_t:s0 style.html
- drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 wiki
顯然上面顯示的結果中的09、16兩行的許可權與其他網站目錄不同。
再檢視selinx的工作狀態,判斷是不是SELinux引起的。
- [root@localhost httpd]# sestatus
- SELinux status: enabled
- SELinuxfs mount: /selinux
- Current mode: enforcing
- Mode from config file: enforcing
- Policy version: 24
- Policy from config file: targeted
這就是導致網站許可權不正確的原因。
我猜測可能是在selinux啟用時對目錄或檔案進行操作導致的。因為最近我對SELinux進行了升級(以前沒有遇到)。
PS:最新的原因分析請參見《對SELinux許可權發生變化的解釋》一文。
所以使用chcon更改SELinux許可權以及顯示結果如下:
setenforce 0 #必須暫時停止SELinux,否則可能導致操作失敗。
chcon -t httpd_sys_content_t -R /var/www/html/home_start/ #R引數是遞迴操作的意思
經過修改就會發現SELinux的對應許可權已經和其他目錄相同了!都是httpd_sys_content_t。
- [root@localhost html]# setenforce –help
- usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
- [root@localhost html]# setenforce 0
- [root@localhost html]# cd
- [root@localhost ~]# ls /var/www/html/ -Z
- ……
- drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 home_start
- ……
- [root@localhost ~]# chcon -t httpd_sys_content_t -R /var/www/html/home_start/
- [root@localhost ~]# ls /var/www/html/home_start/ -Z
- ……
- -rw-r–r–. root root unconfined_u:object_r:httpd_sys_content_t:s0 authorize.php
- ……
然後,再次開啟瀏覽器輸入地址,驗證能否訪問,如果可以訪問就可以進行下一步配置了!
最後,還是那句話,遇到問題一定要仔細分析,儘可能的通過自己的努力和分析發現問題所在,這樣才能體會到解決問題的快樂!
本文轉自 urey_pp 51CTO部落格,原文連結:http://blog.51cto.com/dgd2010/831098,如需轉載請自行聯絡原作者
相關文章
- 更新完 zsh 說我目錄許可權問題的解決
- 解決 PBootCMS 網站出現的“會話目錄寫入許可權不足”的問題boot網站會話
- Android SELinux avc dennied許可權問題解決方法AndroidLinux
- IIS 中 ASP.NET 網站的目錄許可權ASP.NET網站
- PbootCMS網站提示:“會話目錄寫入許可權不足”的解決辦法boot網站會話
- Lnmp 網站根目錄檔案許可權LNMP網站
- Linux下目錄的x執行許可權問題Linux
- 網站提示:”會話目錄寫入許可權不足“網站會話
- linux目錄的許可權Linux
- vue許可權問題解決方案Vue
- Linux更改檔案及目錄許可權問題Linux
- PbootCMS網站提示:”會話目錄寫入許可權不足“boot網站會話
- nfs 掛載目錄 root 許可權不夠 ?NFS
- ubuntu下解決wireshark許可權問題Ubuntu
- Linux 目錄與許可權詳解Linux
- Linux 許可權管理之目錄許可權限制Linux
- 【LIUNX】目錄或檔案許可權,許可權授予
- ORA-07391: sftopn: fopen error, 目錄許可權問題Error
- 通過設定目錄組標誌位解決dmp檔案讀許可權問題
- linux中許可權對檔案和目錄的作用Linux
- apache+php 的匿名FTP功能目錄許可權設定問題(轉)ApachePHPFTP
- PbootCMS提示:“會話目錄寫入許可權不足”的解決辦法boot會話
- Android SELinux許可權AndroidLinux
- Linux 目錄許可權研究Linux
- Swift 中 Selector 方法的訪問許可權控制問題Swift訪問許可權
- 帝國CMS遷移網站後出現Create path fail: (建立目錄不成功!請檢查目錄許可權 )的解決辦法網站AI
- 帝國CMS提示建立目錄不成功,請檢查目錄許可權的解決辦法
- 改變檔案或目錄的訪問許可權命令(轉)訪問許可權
- moderator permission的許可權問題
- Vue設定許可權列表目錄Vue
- 帆軟——目錄及許可權配置
- 解決root使用者對HDFS檔案系統沒有許可權的問題
- Linux的檔案許可權與目錄配置Linux
- 檢視使用者的目錄操作許可權
- Oracle中常用的目錄許可權設定命令Oracle
- 用無程式碼解決CRM角色許可權問題
- autohotkey透過com物件控制excel的許可權問題物件Excel
- Linux改變檔案或目錄的訪問許可權命令Linux訪問許可權