1.打開配置文件Apache->httpd.conf,如圖1.1所示:
2.ctrl+f查找Include conf/extra/httpd-vhosts.conf,去掉前面的#號,如圖2.1;默認情況下httpd-vhosts.conf不會被加載執行,所以要去掉注釋,來執行我下步的配制。
3.打開wamp\bin\apache\apache2.4.9\conf\extra,extra目錄下的httpd-vhosts.conf配置文件,添加配制信息
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "D:\www01" ? //自己設置的站點跟目錄
ServerName testwww01.com ?//虛擬域名順便來,順便說一下端口也80也可以更改
ServerAlias testwww01.com
? <Directory "D:/www01"> //注意這里是斜杠
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
如出現服務器啟動不了可以試試在此前加入
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "D:\wamp\www" //默認的那個站點目錄,你目錄路徑是什么就改為什么。
ServerName localhost
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
4.修改本地hosts文件,hotst里面的域名要與上面配置文件里面相對應,其路徑為:C:\Windows\System32\drivers\etc\hosts ,hosts選擇文本編輯打開
在此后加入剛設置的虛擬域名:
127.0.0.1? ? ? ?testwww01.com
虛擬域名最終解釋為本機IP 127.0.0.1
5.測試,在D:\www01下放入測試文件。
文件內容:
重啟服務器即可訪問。使用testwww01.com訪問。