1.用記事本或Sublime Text打開httpd.conf
ctrl + f 搜索httpd-vhosts.conf
將
#Include conf/extra/httpd-vhosts.conf
的#號去掉保存
2.打開extra/httpd-vhosts.conf
添加如下內容:
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "E:/your_web_root" ServerName your.web.com ErrorLog "logs/your_web_error.log" CustomLog "logs/your_web_access.log" common </VirtualHost>
3.本地測試的話,還需要在hosts文件中配置一個域名解析條目,在C:/windows/system32/drivers/etc/目錄下找到hosts文件
4.完成以上步驟后,重啟Apahce就可以了
重點來了
這時虛擬主機的域名www.web.com可以正常訪問,但是localhost就不能訪問了。報錯如下:
解決:
在httpd.conf文件中有一行代碼是需要注釋掉的
ServerName localhost:80
把ServerName這一行代碼注釋掉就可以了
也許你的httpd.conf文件中并不是localhost:80 這個值,可能是ServerName a.com:80 ; 都一樣,直接注釋掉就可以使用。
之后無論開啟或者關閉虛擬主機,localhost都可以正常訪問。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。