1.找到Apache的\conf目錄下的httpd.conf檔案,開啟它,找到下面這兩行:
# Virtual hosts#Include conf/extra/httpd-vhosts.conf
把它改成下面這樣:
# Virtual hostsInclude conf/extra/httpd-vhosts.conf
意思是啟用虛擬機器主機的設定檔案httpd-vhosts.conf,虛擬機器主機的設定都在這個檔案下
設定,不用去改httpd.conf,這樣比較清晰。
2.找到Apache的\conf\extra目錄下的httpd-vhost.conf這個檔案。
開啟它的時候裡面已經含有像下面這樣的內容:
–虛擬機器主機配置開始
<VirtualHost *:80>ServerAdmin webmaster@dummy-host.localhostDocumentRoot “C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host.localhost”ServerName dummy-host.localhostServerAlias www.dummy-host.localhostErrorLog “logs/dummy-host.localhost-error.log”CustomLog “logs/dummy-host.localhost-access.log” common</VirtualHost>
COPY上面這幾行,關鍵是:把
DocumentRoot “”–虛擬機器主機的目錄,即網域名稱對應的根目錄
ServerName dummy-host.localhost–你想要的網域名稱。
還要在每個虛擬機器主機配置開始前加入以下內容:
<Directory “c:\test”>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
其中:
<Directory “c:\test”> –這是你的虛擬機器主機的被授權的目錄
一般與
DocumentRoot “”–虛擬機器主機的目錄,即網域名稱對應的根目錄
相同。
Allow from all –這句是重點,只要allow別人才行訪問上面定義的目錄,
否則在IE或firefox訪問時會顯示503錯誤,即禁止訪問。
如果你不想在httpd-vhost.conf 裡加入
<Directory “c:\test”>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
那麼你也可以這樣做:
在httpd.conf裡找到以下內容:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
這是Apache預設的設定,最後一行是這樣的
Deny from all
意思是拒絕所有訪問對根目錄的訪問,別人是訪問不了你的網站的,
所以要改成
Allow from all
不過還是建議用第一種方法,即修改httpd-vhost.conf的內容,這樣比較清楚,也比較安全。
這樣apache的設定就完成了,不過還要做下面這一步。
3.還有關鍵的一步:
這一步不做,一定不行因為你本地的機器沒有DNS解析。
找到C:\WINDOWS\system32\drivers\etc目錄下的hosts檔案
加上這樣的記錄
127.0.0.1 demoa–這個是你的網域名稱,你要設定多少個虛擬機器主機,就要加多少行這樣的記錄。
OK,現在你可以設定N+1個網域名稱了。
也可以參考一下這個地址:http://httpd.apache.org/docs/2.0/vhosts/examples.html
範例:
--------------------------------------------------------------------------
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.localhost
DocumentRoot /www/docs/dummy-host.localhost
ServerName dummy-host.localhost
ServerAlias www.dummy-host.localhost
ErrorLog logs/dummy-host.localhost-error_log
CustomLog logs/dummy-host.localhost-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.localhost
DocumentRoot /www/docs/dummy-host2.localhost
ServerName dummy-host2.localhost
ErrorLog logs/dummy-host2.localhost-error_log
CustomLog logs/dummy-host2.localhost-access_log common
</VirtualHost>
<Directory "D:\phpwork">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.localhost
DocumentRoot D:\phpwork
ServerName localhost
ErrorLog logs/dummy-host2.localhost-error_log
CustomLog logs/dummy-host2.localhost-access_log common
</VirtualHost>
<Directory "D:\phpwork\phpMyAdmin">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.localhost
DocumentRoot D:\phpwork\phpMyAdmin
ServerName phpMyAdmin.local
ErrorLog logs/dummy-host2.localhost-error_log
CustomLog logs/dummy-host2.localhost-access_log common
</VirtualHost>
<Directory "D:\phpwork\test">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.localhost
DocumentRoot D:\phpwork\test
ServerName test.local
ErrorLog logs/dummy-host2.localhost-error_log
CustomLog logs/dummy-host2.localhost-access_log common
</VirtualHost>
原文轉載地址:http://hi.baidu.com/xiyi2008/item/ebfc92001cd6cc10cd34ea64