问题
打开 Wamp主页面在VirtualHost一项出现以下错误:
ServerName localhost:8080 is not defined into hosts file.
—
可以看到最后一项提示hosts file error并且提示Error(s) see below
网上未找到其他有关教程,尝试更改Apache 下的“httpd-vhosts.conf”文件
1.左单击状态栏wampserver图标
2.点击Apache栏
3.在“文件&文档”一栏找到“httpd-vhosts.conf”单击打开
4.如下图所示
5.尝试将ServerName localhost更改为 ServerName localhost:8080
6.保存回到主页刷新后依然提示出错
错误变为syntax error
The ServerName localhost:8080:8080 has syntax error in file D:/wamp64/bin/apache/apache2.4.51/conf/extra/httpd-vhosts.conf
意为语法错误
7.撤回更改
错误恢复到原来的样子
8.尝试从状态栏直接启动虚拟主机localhost
依然左键wampserver图标,点击 “Your VirtualHosts”,选择提示出错的“localhost:8080”打开
9.弹出弹窗
提示“In the httpd-vhosts.conf file:
‘localhost:8080’ ServerName
is not defined into ‘C:/WINDOWS/system32/drivers/etc/hosts’ file.”
10.因此找到’C:/WINDOWS/system32/drivers/etc/hosts’ file.”文件
选择任意编辑器打开,我这里用的是vscode
打开之后如上图
11.将第二个localhost更改为localhost:8080
12.保存时出现提示
13.选择以管理员身份重试,选择是
14.此时在回到主页面刷新
16.报错解决
总结
在状态栏内点击报错的虚拟主机打开,根据提示的路径找到hosts文件对其进行更改即可解决“ServerName localhost:8080 is not defined into hosts file.”报错。