找到host文件:
C:\Windows\System32\drivers\etc\hosts
用記事本或者其他編輯器打開host文件,並在其中增加幾行代碼。
這裏輸入兩個測試域名:
666.666.com
777.777.com
在hosts這麼增加:
127.0.0.1 666.666.com
127.0.0.1 777.777.com
修改httpd.conf文件:
打開文件:xxx\xampp\apache\conf\httpd.conf
找到#LoadModule vhost_alias_module modules/mod_vhost_alias.so
將前面的“#”刪除
LoadModule vhost_alias_module modules/mod_vhost_alias.so
進入:
進入XXX\xampp\apache\conf\extra目錄
找到httpd-vhosts.conf文件
講一下代碼複製兩邊(這裏是兩個虛擬主機):
##<VirtualHost *:80>
##ServerAdmin [email protected]
##DocumentRoot "H:/xampp/htdocs/dummy-host.example.com"
##ServerName dummy-host.example.com
##ServerAlias www.dummy-host.example.com
##ErrorLog "logs/dummy-host.example.com-error.log"
##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>
修改如下:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "F:/WebTemplates/shop/www"
ServerName 666.777.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "H:\xampp\htdocs"
ServerName 666.666.com
ErrorLog "logs/dummy-host.example666.com-error.log"
CustomLog "logs/dummy-host.example666.com-access.log" common
</VirtualHost>
保存文件,重啓apache服務器瀏覽器訪問及可。
xampp下面初次使用虛擬主機可能會遇到:
xampp Apache Access forbidden! Error 403