# Virtual hosts #Includeconf/extra/httpd-vhosts.conf
去掉前面的#,這樣就開啟了httpd-vhosts虛擬主機文件。這時候重啟wamp環(huán)境,無法打開localhost,需要在httpd-vhosts.conf配置一下。
2,用記事本打開httpd-vhosts文件,配置好localhost虛擬主機,參照httpd-vhosts文件中實例,修改成如下:
ServerAdminwebmaster@dummy-host.localhost DocumentRoot"D:wampwww" ServerNamelocalhost ServerAliaslocalhost ErrorLog"logs/dummy-host.localhost-error.log" CustomLog"logs/dummy-host.localhost-access.log" common
修改配置如下:DocumentRoot 修改為本地wamp環(huán)境下的www目錄(如:D:wampwww)ServerName改為localhost3,重啟Apache,發(fā)現localhost可以正常打開,配置localhost比較簡 單。
實例二,Apache配置 test.biuuu.com虛擬主機步驟
1,方法同上,復制配置代碼修改如下:

ServerAdmintest@biuuu.com DocumentRootE:WebRootbiuuu ServerNametest.biuuu.com ErrorLog"logs/dummy-host2.localhost-error.log" CustomLog"logs/dummy-host2.localhost-access.log" common
2,打開host文件(C:WINDOWSsystem32driversetchosts),增加一行代碼
127.0.0.1 test.biuuu.com
3,在瀏覽器中打開test.biuuu.com,發(fā)現如下錯誤403 Forbidden錯誤ForbiddenYou don't have permission to access / on this server.
分析:這主要是目錄訪問權限沒有設置,需要設置對目錄的訪問權!
4,打開httpd文件,找到 如下語句
OptionsFollowSymLinks AllowOverride None Order deny,allow Deny from all
復制以上代碼,并進行目錄修改,把/替換為E:WebRootbiuuu,修改virtualHost代碼如下
在瀏覽器中測試發(fā)現還是打不開,提示如上403 Forbidden錯誤,修改其中的Deny from all為allowfrom all
5,重啟Apache,虛擬主機配置成 功!
注意事項1,目錄路徑,如E:WebRootbiuuu2,訪問權限,如上Deny from all修改為allow from all3,host文件,配置虛擬域名host指向4,httpd文件,打開Include conf/extra/httpd-vhosts.conf模塊5,httpd-vhosts文件,配置虛擬主機
使用 Apache配置httpd-vhosts虛擬主機對于開發(fā)人員來說比較簡單,但卻非常重要,僅供參考!
PS: D:wampalias 也可以這樣配置虛擬域名,和例二相同效果
ServerName blog.ccServerAlias blog.ccDocumentRoot "D:wampwwwblog"Options All FollowSymLinks IncludesNOEXECIndexesDirectoryIndex index.html index.htmdefault.htm index.php default.php index.cgi default.cgi index.shtmlindex.aspx default.aspx AllowOverride AllOrder Deny,AllowAllow from all
愛華網



