網上查了幾個資料,作法以下:好比想配置兩個www.web1.com www.web2.com站點php
打開httpd.conf ,而後添加:html
1 <VirtualHost *:80> 2 DocumentRoot "d:/github/web1" 3 ServerName www.web1.com 4 </VirtualHost> 5 6 <VirtualHost *:80> 7 DocumentRoot "d:/github/web2" 8 ServerName www.web2.com 9 </VirtualHost>
而後我試了n次,發現訪問www.web2.com,打開的是www.web1.com,也就是說只有第一個虛擬站點設置生效了。而後我懷疑是否是DocumentRoot 、<Directory> 或者端口問題,因而改了屢次,仍是不行。git
找了多篇文章,終於試驗成功了,打開httpd.conf,而後添加:github
NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot "d:/github/web1" ServerName www.web1.com </VirtualHost> <VirtualHost *:80> DocumentRoot "d:/github/web2" ServerName www.web2.com </VirtualHost>
從新訪問www.web2.com, 正確的打開了www.web2.com內容。web
這段虛擬站點的設置我建議設置在httpd.conf裏面,能夠將httpd.conf的 #Include conf/extra/httpd-vhosts.conf 的註釋#去掉,apache
而後在httpd-vhosts.conf裏面設置,這時驚奇的發現httpd-vhosts.conf裏面有這句 NameVirtualHost *:80spa
真的是網上找資料很容易誤入歧途,不少人寫文章不親自試驗,就摘抄,結果誤人子弟。code
最後分享個文章裏面總結了apache配置:htm