在我的 Ubuntu 16.4 VM 中,我已成功設定 Apache 2.4 並設定了多個虛擬主機。我想查看伺服器狀態,但我的第一個虛擬主機一直阻止這種情況。我已經閱讀並重新閱讀了有關此內容的 Apache 2.4 文件。我將以下內容放入 /etc/apache2/apache.conf 中,然後放入 /etc/apache2/mods-enabled/status.conf 中,最後放入 /etc/apache2/sites-enabled/0firstvhost.conf 中
<Location "/server-status">
SetHandler server-status
Require ip 10.211.55.0/24
</Location>
在閱讀 Apache 文件和 ServerFault 中有關此主題的許多帖子時,我嘗試了許多適用於 Apache 2.4 的變體
我可以透過在運行時查看 mod_status 來驗證它是否正在運行
sudo apachectl -M | grep status
當然,我每次都會檢查 apachectl configtest 並重新啟動 apache2 服務,看看是否可以瀏覽到 10.211.55.3/server-status,但 Drupal PHP 應用程式不斷幹擾。該虛擬主機的根目錄下沒有 .htaccess。
我已將該指令放置在該指令的內部和外部。
我在虛擬機器的 IP 位址以及虛擬機器運行中檢查瀏覽器
curl localhost/server-status
curl 10.211.55.3/server-status
首先讀取 Drupal 應用程式。接下來要嘗試什麼?謝謝,薩姆
答案1
發現這個建議預設站點的 .htaccess 阻止了 mod_status從工作中。他們的解決方案對我不起作用,但由於我正在使用虛擬主機,所以我可以建立一個沒有 .htaccess 的虛擬主機。我在 Debian 的 /etc/hosts 檔案中新增了任意主機:
127.0.0.1 foo.org
在我的其他虛擬主機中建立了一個空目錄,並建立了一個新網站並啟用了它。
<Directory /home/foo.org>
</Directory>
<Location /server-status>
SetHandler server-status
Require local
Require ip 127.0.0.1
Require ip ::1
</Location>
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName foo.org
</VirtualHost>
所以在本地主機上我可以看到數據
curl foo.org/server-status
答案2
我也遇到了我的問題虛擬主機 /etc/sites-enabled/example.conf
處理 http://localhost/server-info 的請求,我實際上希望由其處理模組資訊。
# File /etc/sites-enabled/example.conf
<VirtualHost *:80>
ServerName example.com
# ...
</VirtualHost>
問題是恕我直言,如果某些請求與任何配置的不匹配,Apache 有預設的後備請求處理行為虛擬主機的伺服器名稱(看1,2)。作為模組資訊的預設設定檔/etc/apache2/mods-available/info.load
並且/etc/apache2/mods-available/info.conf
不指定自己的虛擬主機和伺服器名稱,我猜阿帕契的後備開始了,有我的example.conf 虛擬主機處理 http://localhost/server-info 的請求。
我透過以下方式解決了該問題:
建立一個檔案/etc/apache2/mods-available/localhost-server-info.load
(注意mods-available
)。這是一個複製原文info.load
:
LoadModule info_module /usr/lib/apache2/modules/mod_info.so
建立一個檔案/etc/apache2/sites-available/localhost-server-info.conf
(注意sites-available
)。這是對原版的改編info.conf
,將其內容包裝在一個虛擬主機並提供一個伺服器名稱:
# Get mod_info information by requesting http://localhost/server-info
#
# Enable by executing
# service apache2 stop
# a2dismod info
# a2enmod localhost-server-info
# a2ensite localhost-server-info
# service apache2 start
#
# Disable by executing
# service apache2 stop
# a2dissite localhost-server-info
# a2dismod localhost-server-info
# service apache2 start
<IfModule mod_info.c>
<VirtualHost *:80>
# Adapt ServerName to your needs
# Avoid ServerName collision with any other active VirtualHosts
ServerName localhost
<Location /server-info>
SetHandler server-info
# Adapt Require to your needs
# Require local
# Require ip 192.0.2.0/24
</Location>
</virtualHost>
</IfModule>
禁用原來的資訊模組(如果它仍然啟用)並啟用新的本地主機伺服器資訊模組和地點:
service apache2 stop
a2dismod info
a2enmod localhost-server-info
a2ensite localhost-server-info
service apache2 start
- http://example.com/server-info現在應該由example.comVirtualHost(可能顯示 404 頁)。
- http://localhost/server-info 現在應該由模組資訊。
- http://127.0.0.1/伺服器信息以及其他未配置的伺服器名稱s 應該根據 Apache 的後備處理進行處理,例如在我的範例中example.comVirtualHost(可能顯示 404 頁)。