Fedora 23 上的新 Apache 設定出現 500 錯誤。

Fedora 23 上的新 Apache 設定出現 500 錯誤。

好吧,我覺得有點奇怪。

因此,我使用 Apache 的大部分經驗都是在 Ubuntu 伺服器安裝上進行的。但在我的伺服器硬碟經歷了災難性故障(謝天謝地,我從中恢復了所有資料)後,我抓住機會切換到最新的 Fedora 伺服器。造成這種情況的原因有幾個,但最重要的一個是 Ubuntu Server 安裝程式的問題,特別是它無法辨識我的無線鍵盤,以及我最後一個有線鍵盤壞了。

無論如何,我安裝了 httpd (apache)、php、postgresql 和 php-pgsql。然後我將所有舊網站頁面移至新的 Web 目錄 (/var/www/html/)。然後我得到了 500 錯誤。

我決定冒險從頭開始。將我的網頁移到一邊(進入 /var/www/html2/ ),並建立一個小頁面來測試它。只有基本的 HTML,沒有什麼花俏的內容,沒有 PHP,只有基礎。

<html>
<head>
<title>HOME!!!</title>
</head>
<body>
<h1>THIS WORKS!!!</h1>
</body>
</html>

它加載沒有問題。

然後我將每個頁面移回主資料夾(目前 .htaccess 除外),我剛剛建立的頁面仍然正常運作。懷疑問題出在 php 上,我在底部加入了一些 php 程式碼:

echo 'hello';

工作得很好。

這就是奇怪的地方。我嘗試將網站中的舊 footer.php 包含到這個小測試頁面中,這就是問題開始的地方。頁腳根本無法載入。

<?php include 'footer.php'; ?>

頁面的其餘部分加載,只是頁腳不加載。然後,我高興地把頁腳檔案的所有內容複製到一個名為 footer2.php 的新檔案中,並將測試頁面更改為引用 footer2.php,並且它完全加載,沒有任何問題。

所以我終於認為我找到了一些東西,所以我更改了 footer.php 的權限以匹配 footer2.php。它仍然無法加載。

由於某種原因,footer.php 不會加載,但 footer2.php 會加載。

那麼有什麼差別呢!

這些文件完全相同!這是證明:

[blackwidower@Twilight html]$ md5sum footer*
257cbd773ed765deb5ad0015852cdf20  footer2.php
257cbd773ed765deb5ad0015852cdf20  footer.php
[blackwidower@Twilight html]$ ls -l footer*
-rw-rw-r--. 1 blackwidower blackwidower 1271 Feb  1 00:08 footer2.php
-rw-rw-r--. 1 blackwidower blackwidower 1271 Feb  1 00:08 footer.php

然而,一個加載,另一個不加載。

我可以做些什麼來找到可以分隔這些文件的更多資料嗎?

作為參考,這裡是 apache error_log:

[Mon Feb 01 00:14:15.160242 2016] [core:notice] [pid 1800] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Mon Feb 01 00:14:15.161310 2016] [suexec:notice] [pid 1800] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.7.2. Set the 'ServerName' directive globally to suppress this message
[Mon Feb 01 00:14:15.192180 2016] [auth_digest:notice] [pid 1800] AH01757: generating secret for digest authentication ...
[Mon Feb 01 00:14:15.192361 2016] [http2:warn] [pid 1800] AH02951: mod_ssl does not seem to be enabled
[Mon Feb 01 00:14:15.193015 2016] [lbmethod_heartbeat:notice] [pid 1800] AH02282: No slotmem from mod_heartmonitor
[Mon Feb 01 00:14:15.218713 2016] [mpm_prefork:notice] [pid 1800] AH00163: Apache/2.4.18 (Fedora) PHP/5.6.17 configured -- resuming normal operations
[Mon Feb 01 00:14:15.218762 2016] [core:notice] [pid 1800] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Mon Feb 01 00:14:43.969957 2016] [:error] [pid 1801] [client 192.168.7.7:49878] PHP Fatal error:  Call to undefined function displayCopyrightInfo() in /var/www/html/footer2.php on line 13
[Mon Feb 01 00:14:44.086110 2016] [core:error] [pid 1802] (13)Permission denied: [client 192.168.7.7:49880] AH00035: access to /images/cc-by-nc-nd-88x31.png denied (filesystem path '/var/www/html/images/cc-by-nc-nd-88x31.png') because search permissions are missing on a component of the path, referer: http://192.168.7.2/index2.php
[Mon Feb 01 00:14:44.087064 2016] [core:error] [pid 1804] (13)Permission denied: [client 192.168.7.7:49882] AH00035: access to /images/valid-xhtml10-blue.png denied (filesystem path '/var/www/html/images/valid-xhtml10-blue.png') because search permissions are missing on a component of the path, referer: http://192.168.7.2/index2.php
[Mon Feb 01 00:14:44.087737 2016] [core:error] [pid 1806] (13)Permission denied: [client 192.168.7.7:49884] AH00035: access to /images/vcss-blue.png denied (filesystem path '/var/www/html/images/vcss-blue.png') because search permissions are missing on a component of the path, referer: http://192.168.7.2/index2.php
[Mon Feb 01 00:15:47.538488 2016] [:error] [pid 1808] [client 192.168.7.7:49890] PHP Warning:  include(footer.php): failed to open stream: Permission denied in /var/www/html/index2.php on line 7
[Mon Feb 01 00:15:47.538534 2016] [:error] [pid 1808] [client 192.168.7.7:49890] PHP Warning:  include(): Failed opening 'footer.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/index2.php on line 7

編輯:

根據一個人的建議。我運行了 ls -Z。這是我發現的:

unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/footer2.php
               system_u:object_r:fusefs_t:s0 /var/www/html/footer.php

所以我發現了一個差異。問題是:這是什麼意思,以及如何修正它?

答案1

所以我發現了一個差異。問題是:這是什麼意思,以及如何修正它?

擴展使用者 @Dirk 指出的內容,SELinux 是一個依賴「上下文」來提高系統安全性的系統,上下文描述了可以對某個檔案或目錄執行哪些類型的操作,或者一個檔案可以用來做什麼。在本例中,footer2.php具有 的上下文httpd_sys_content_t,因此這意味著該文件可用於“http 目的”,您需要做的是添加相同的上下文標籤,footer.php以便可以透過 SELinux 安全系統存取它,或者只是恢復父目錄上的上下文(預設情況下,在大多數系統上,該/var/www位置中的檔案設定為標籤為“http 目的")。另一種方法是完全停用 SELinux,但這不是一個好的做法。

所以,

若要(永久)設定檔案的上下文標籤footer.php

semanage fcontext -a -t httpd_sys_content_t /var/www/html/footer.php
restorecon /var/www/html/footer.php

您可以對父目錄(及其所有內容)執行相同的操作:

semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?"
restorecon -R "/var/www/html(/.*)?"

您可以在以下位置找到更多資訊:面向安全增強 Linux 的紅帽客戶門戶

相關內容