直接注释掉就可以使用 之后无论开启或者关闭虚拟主机

时间:2022-01-03 06:37:55

win10系统配置虚拟主机
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就可以了
重点来了
这时虚拟主机的域名可以正常访谒,,但是localhost就不能访谒了。报错如下:

直接注释掉就可以使用 之后无论开启或者关闭虚拟主机

解决:
在httpd.conf文件中有一行代码是需要注释失的
ServerName localhost:80
把 ServerName 这一行代码注释失就可以了
也许你的httpd.conf文件中并不是localhost:80 这个值,可能是 ServerName a.com:80 ; 都一样,直接注释失就可以使用
之后无论开启或者*虚拟主机,localhost都可以正常访谒。

直接注释掉就可以使用 之后无论开启或者关闭虚拟主机