
我在使用 apache 時遇到一些奇怪的權限錯誤,我可以存取 apache 主目錄下的文檔,但不能存取任何其他目錄下的文檔。
當我查看 Apache error_log 時,它顯示
[error] (13)Permission denied: access to / denied
我將檔案和資料夾權限設為 777,並且我知道我的 httpd.conf 設定正確。
這是奇怪的事情
當我對 apache 目錄中的檔案執行此操作時,它工作正常
su -s /bin/bash -c "cat /usr/local/apache2/htdocs/index.html" apache
<html><body><h1>It works!</h1></body></html>
當我對具有相同權限的外部文件執行此操作時,我得到
su -s /bin/bash -c "cat /var/www/html/index.html" apache
cat: /var/www/html/index.html: Permission denied
我認為這一定是 selinux 的事情,所以我透過在 /etc/selinux/config 中設定 SELINUX=disabled 並重新啟動伺服器來關閉它,但這不起作用。
我正在使用全新安裝的 CentOS 4.8,並且我的 Web 目錄是從我的主 Web 伺服器進行 rsync 的。
更新
ls -lZ
Sorry, this option can only be used on a SELinux kernel.
id apache
uid=48(apache) gid=48(apache) groups=48(apache)
ls -l /var /var/www /var/www/html /var/www/html/index.html
-rwxrwxrwx 1 apache apache 7 Jan 18 15:36 /var/www/html/index.html
/var:
total 192
drwxr-xr-x 2 root root 4096 Dec 28 09:04 account
drwxr-xr-x 9 root root 4096 Dec 28 09:04 cache
drwxr-xr-x 3 netdump netdump 4096 Dec 28 09:04 crash
drwxr-xr-x 3 root root 4096 Dec 28 09:04 db
drwxr-xr-x 2 root root 4096 Dec 29 13:31 doc
drwxr-xr-x 3 root root 4096 Dec 28 09:04 empty
drwxr-xr-x 3 root root 4096 Dec 28 09:06 ftp
drwxr-xr-x 7 root root 4096 Jan 15 10:24 httpdocs
drwxr-xr-x 7 root root 4096 Dec 29 13:31 installed_packages
drwxr-xr-x 24 root root 4096 Jan 4 09:54 lib
drwxr-xr-x 2 root root 4096 Feb 21 2005 local
drwxrwxr-x 6 root lock 4096 Jan 19 04:02 lock
drwxr-xr-x 12 root root 4096 Jan 19 07:50 log
lrwxrwxrwx 1 root root 10 Dec 28 09:03 mail -> spool/mail
drwxr-x--- 5 root named 4096 Jul 29 14:10 named
drwxr-xr-x 2 root root 4096 Feb 21 2005 nis
drwxr-xr-x 2 root root 4096 Feb 21 2005 opt
drwxr-xr-x 2 root root 4096 Feb 21 2005 preserve
drwxr-xr-x 22 root root 4096 Jan 19 07:44 run
drwxr-xr-x 14 root root 4096 Dec 28 09:04 spool
drwxrwxrwt 2 root root 4096 Jan 15 04:30 tmp
drwx------ 2 root root 4096 Feb 21 2005 tux
drwxr-xr-x 8 root root 4096 Nov 12 05:56 www
drwxr-xr-x 2 root root 4096 Jan 19 10:26 www2
drwxr-xr-x 3 root root 4096 Dec 28 09:04 yp
/var/www:
total 48
drwxr-xr-x 2 root root 4096 Nov 12 05:56 cgi-bin
drwxr-xr-x 3 root root 4096 Dec 28 09:16 error
drwxr-xr-x 2 root root 4096 Jan 18 15:36 html
drwxr-xr-x 3 root root 4096 Dec 28 09:16 icons
drwxr-xr-x 13 root root 4096 Dec 28 09:16 manual
drwxr-xr-x 2 webalizer root 4096 Jan 19 04:02 usage
/var/www/html:
total 8
-rwxrwxrwx 1 apache apache 7 Jan 18 15:36 index.html
答案1
根據您發布的內容,我想說您需要授予 apache 訪問 /var 的權限。
答案2
[錯誤] (13)權限被拒絕:存取/被拒絕
CGI 或外掛程式可能會嘗試在 / 中建立檔案。看看您是否可以準確地找出導致錯誤的操作。