我期望能夠構建一個腳本,它將顯示在我的Apache(Ubuntu)開發機器下運行的所有虛擬主機。從php腳本顯示虛擬主機?
到今天爲止,我還沒有發現接近我想要的任何實例或任何東西,這簡直是:
「顯示本機上運行的所有虛擬主機」。 (ServerName,別名等)。
我在想我可能會讀取/ etc/apache2/sites-available文件夾,其中包含虛擬主機的所有conf文件,但在走下這條路之前,我想我會先問到這裏。
我期望能夠構建一個腳本,它將顯示在我的Apache(Ubuntu)開發機器下運行的所有虛擬主機。從php腳本顯示虛擬主機?
到今天爲止,我還沒有發現接近我想要的任何實例或任何東西,這簡直是:
「顯示本機上運行的所有虛擬主機」。 (ServerName,別名等)。
我在想我可能會讀取/ etc/apache2/sites-available文件夾,其中包含虛擬主機的所有conf文件,但在走下這條路之前,我想我會先問到這裏。
可以使用apachectl
(或apache2ctl
)命令信號的httpd
Apache服務器轉儲虛擬主機信息:
apache2ctl -St
通過以下鏈接可使用apachectl發送信號和httpd flags。
下面是它看起來像我的Apache/Ubuntu系統上(我是一個Web開發人員與一羣虛擬主機):
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server 127.0.1.1 (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost 127.0.1.1 (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost adaleco (/etc/apache2/sites-enabled/adaleco:1)
port 80 namevhost amcham (/etc/apache2/sites-enabled/amcham:1)
port 80 namevhost cake (/etc/apache2/sites-enabled/cake:1)
port 80 namevhost cakeplate (/etc/apache2/sites-enabled/cakeplate:1)
port 80 namevhost coord (/etc/apache2/sites-enabled/coord:1)
port 80 namevhost dru1 (/etc/apache2/sites-enabled/dru1:1)
port 80 namevhost flaming (/etc/apache2/sites-enabled/flaming:1)
port 80 namevhost flaming6 (/etc/apache2/sites-enabled/flaming6:1)
port 80 namevhost food (/etc/apache2/sites-enabled/food:1)
port 80 namevhost fun (/etc/apache2/sites-enabled/fun:1)
port 80 namevhost marc (/etc/apache2/sites-enabled/marc:1)
port 80 namevhost sugar (/etc/apache2/sites-enabled/sugar:1)
port 80 namevhost vol (/etc/apache2/sites-enabled/vol:1)
port 80 namevhost xmas (/etc/apache2/sites-enabled/xmas:1)
Syntax OK
嘿,斯科特,爲你做這個工作還是你有其他想法(不知道是否通過腳本你想要一個本地的PHP API)? – 2013-03-27 03:10:13
我想要的是一個php腳本,當我在本地機器上激活時,只會吐出上面顯示的畫面,所以我寫了一個快速的PHP腳本來讀取啓用站點的目錄,並且只是吐出每個文件的內容。不過,我想我會重新使用apache2ctl命令。 謝謝,約翰。完成後,我會發布我的腳本。 – 2013-03-29 14:51:46
我覺得讀conf文件是唯一的出路。 – chrislondon 2013-03-26 20:34:35
虛擬主機文件可以是任何地方或主要conf文件的一部分。如果apache沒有獲取定義的虛擬主機的api,我看不到任何簡單的方法來解決這個問題。除非你保證一定的安裝配置文件。 – 2013-03-26 20:35:39