Apache-2.2

如何使用多個虛擬主機提供不同的本地索引頁面

  • May 31, 2013

目標:執行http://test.local>並從測試站點獲取索引,執行<http://l4.dev 並從 lara4 提供索引。

我不想要的是它可以找到的虛擬主機列表中的第一個索引

應該如何管理多個本地站點?- 最佳實踐 - ( apache 2.2 版)

這就是我添加到 httpd.config 的內容(這是最好的方法嗎, - 直接將其添加到 httpd.config?)

  NameVirtualHost *:80

&lt;VirtualHost *&gt;  
   DocumentRoot "/Users/redres/Webdev/lara4"  
   ServerName l4.dev
   ServerAlias www.l4.dev
&lt;/VirtualHost&gt;
&lt;VirtualHost *&gt;  
   DocumentRoot "/Users/redres/Webdev/testsite"  
   ServerName test.local
   ServerAlias www.test.local
&lt;/VirtualHost&gt;  
&lt;VirtualHost *&gt;   
   DocumentRoot "/Users/redres/Webdev"  
   ServerName localhost  
&lt;/VirtualHost&gt;   

&lt;Directory "/Users/redres/Webdev"&gt;
   Options All
   AllowOverride All
   Order allow,deny
   Allow from All
&lt;/Directory&gt;

這是主機文件

127.0.0.1   test.local
127.0.0.1   l4.dev
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost

謝謝

您將需要一個 NameVirtualHost 指令:

NameVirtualHost *
&lt;VirtualHost *&gt;  
   DocumentRoot "/Users/redres/Webdev/lara4"  
   ServerName l4.local
   ServerAlias www.l4.local
&lt;/VirtualHost&gt;
&lt;VirtualHost *&gt;  
   DocumentRoot "/Users/redres/Webdev/testsite"  
   ServerName test.local
   ServerAlias www.test.local
&lt;/VirtualHost&gt;  
&lt;VirtualHost *&gt;   
   DocumentRoot "/Users/redres/Webdev"  
   ServerName localhost  
&lt;/VirtualHost&gt;   

&lt;Directory "/Users/redres/Webdev"&gt;
   Options All
   AllowOverride All
   Order allow,deny
   Allow from All
&lt;/Directory&gt;

http://httpd.apache.org/docs/2.2/de/vhosts/name-based.html

引用自:https://serverfault.com/questions/512190