我無法讓 apache 跟踪 Web 根目錄之外的符號鏈接,即使權限看起來不錯並且 FollowSymLinks 已打開。詳細資訊如下。
我有兩個世界可讀的文本檔:/tmp/hello
和/var/www/html/hello
.另外,在 webroot 中,我有這兩個檔案的符號連結。兩者看起來都很好。
$ ll /tmp
drwxrwxrwt. 27 root root 4096 Jul 8 13:55 ./
dr-xr-xr-x. 23 root root 4096 Jul 4 23:24 ../
-rw-r--r--. 1 root root 6 Jul 8 13:55 hello
$ ll /var/www/html
drwxr-xr-x. 3 root root 4096 Jul 8 13:56 ./
drwxr-xr-x. 6 root root 4096 Apr 4 12:57 ../
-rw-r--r--. 1 root root 20 Jul 8 14:03 hello
lrwxrwxrwx. 1 root root 5 Jul 8 14:04 link-local -> /var/www/html/hello
lrwxrwxrwx. 1 root root 10 Jul 8 13:56 link-tmp -> /tmp/hello
$ cat /var/www/html/link-local
/VAR/WWW/HTML/HELLO
$ cat /var/www/html/link-tmp
/TMP/HELLO
Apache 可以透過以下連結存取 Web 根目錄:
$ curl http://localhost/link-local
/VAR/WWW/HTML/HELLO
但 Apache 不會遵循以下符號連結/tmp/
:
$ curl http://localhost/link-tmp
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /hellolink on this server.</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at localhost Port 80</address>
</body></html>
這是在 CentOS 6 上; http 以使用者 apache、群組 apache 的身份運作。
為什麼會發生這種情況?我該如何修復它?
答案1
是的,看起來 SELinux 就是罪魁禍首:
-Z 開關將與大多數實用程式配合使用以顯示 SELinux 安全上下文(例如,「ls -Z」、「ps axZ」等)。
$ ll -Z /var/www/html/hello
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/hello
$ ll -Z /tmp/hello
-rw-r--r--. root root unconfined_u:object_r:user_tmp_t:s0 /tmp/hello
兩個目標檔案具有不同的類型 ( httpd_sys_content_t
vs user_tmp_t
),這解釋了可訪問性的差異。
這centos.org 上的 SELinux 頁面解釋了-Z
開關以及更多更多內容。
答案2
您是否在 .htaccess 檔案中設定 FollowSymlinks?或在一個<Directory>
街區?
Apache 2.2 選項文檔建議 FollowSymlinks 僅在這些上下文中工作 - 您可以發布相關配置嗎?
(由於評論點不足而作為答案發布)