win10 apache配置虚拟主机后localhost无法使用的解决方法

Shanon ·
更新时间:2024-09-20
· 692 次阅读

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 webmaster@youremail.com 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都可以正常访问。

您可能感兴趣的文章:在win10和linux上分别安装Python虚拟环境的方法步骤win10 装centos7 虚拟机利用win10自带虚拟机hyper-v安装centos7方法详解Windows 10系统安装虚拟专用网客户端工具(图文教程)



方法 win localhost Apache

需要 登录 后方可回复, 如果你还没有账号请 注册新账号