Apache2(XAMPP)虛擬主機指令不起作用(顯然)

Apache2(XAMPP)虛擬主機指令不起作用(顯然)

我有一些設定基於 IP 的虛擬主機時所出現的問題。首先,我在 Windows 7 上使用 apachefriends 提供的最新 XAMPP(XAMPP 1.7.7 和 Apache 2.2.21)。

「主」伺服器(來自httpd.conf)的基本功能運作完美。但現在我想設定多個具有不同 IP 位址的虛擬主機,因為我將網路卡配置為使用從 192.168.2.95 到 192.168.2.105 的所有 IP 位址。

這是虛擬主機條目:

<VirtualHost 192.168.2.96:80>
    DocumentRoot "/xampp/hegedocs/www"
    ServerName 192.168.2.96:80
</VirtualHost>

httpd -D DUMP_VHOSTS說:

PS G:\xampp\apache\bin> ./httpd -D DUMP_VHOSTS
VirtualHost configuration:
192.168.2.96:80        192.168.2.96 (G:/xampp/apache/conf/extra/httpd-vhosts.conf:45)
Syntax OK

但我無法存取虛擬主機,apache 似乎也無法監聽 192.168.2.96:80 - 沒有顯示該位址的條目netstat -a -b

答案1

我發現了問題:基於 IP 的虛擬主機不起作用。只需在主機檔案中定義幾個名稱(foo.localhost、bar.localhost 都對應到相同 IP 位址),然後使用基於名稱的虛擬主機就可以正常運作。當然,這不像 IP 位址那樣可移植,因為網路中的其他機器自然不知道這些名稱......但是,只要它能以某種方式工作......

答案2

答案3

您可以嘗試添加以下一些基本內容,以確保您獲得正確的連接埠。

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

下面是來自 appache 的一個範例,它應該是什麼樣子:

<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example1.com

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example2.org

# Other directives here

</VirtualHost>

我相信您以前已經見過這一點,但有時回顧一下簡單的事情會有所幫助。

我的設定運作正常,使用 ServerName www.example.com 在 1 個機器上執行 2 個網站。

希望這可以幫助!

答案4

確保 apache 知道 vhost.conf 檔案在哪裡。在 httpd.conf 的底部,您可能需要取消註釋

Include conf/*.conf

相關內容