WAMP局域网通过虚拟主机名无法访问,使用服务器IP则正常
远程访问WAMP虚拟主机名的解决方案
问题描述
本地使用WAMP 3.2搭建站点,通过localhost或自定义虚拟主机名euroscore.local均可正常访问,但远程设备访问时,仅能通过服务器IP加路径(如192.168.0.81/Euro)打开站点,直接使用虚拟主机名会提示“无法访问此网站”。修改配置后均已重启服务,当前httpd-vhosts.conf配置如下:
# Virtual Hosts # <VirtualHost *:80> ServerName localhost ServerAlias localhost DocumentRoot "${INSTALL_DIR}/www" <Directory "${INSTALL_DIR}/www/"> Options +Indexes +Includes +FollowSymLinks +MultiViews AllowOverride All Require all granted Allow from all </Directory> </VirtualHost> # <VirtualHost *:80> ServerName euroscore.local DocumentRoot "c:/wamp64/www/euro" <Directory "c:/wamp64/www/euro/"> Options +Indexes +Includes +FollowSymLinks +MultiViews AllowOverride All Require all granted Allow from all </Directory> </VirtualHost>
解决步骤
配置远程设备的hosts文件
自定义虚拟主机名euroscore.local仅在本地系统有解析记录,远程设备无法识别该域名对应的服务器IP,需手动添加映射:- Windows:打开
C:\Windows\System32\drivers\etc\hosts,添加一行192.168.0.81 euroscore.local(替换为你的服务器实际局域网IP) - 其他系统(macOS/安卓/iOS):找到对应系统的hosts文件编辑入口,添加相同的IP与域名映射规则
- Windows:打开
确认Apache核心配置
- 打开
httpd.conf,确保虚拟主机配置文件的引用未被注释:Include conf/extra/httpd-vhosts.conf - 检查Apache监听设置,确保监听所有IP的80端口:
Listen 0.0.0.0:80 Listen [::0]:80
- 打开
优化虚拟主机配置(可选)
若需要支持多域名/IP访问,可给目标虚拟主机添加ServerAlias,补充服务器IP作为别名:<VirtualHost *:80> ServerName euroscore.local ServerAlias euroscore.local 192.168.0.81 DocumentRoot "c:/wamp64/www/euro" <Directory "c:/wamp64/www/euro/"> Options +Indexes +Includes +FollowSymLinks +MultiViews AllowOverride All Require all granted Allow from all </Directory> </VirtualHost>排查防火墙拦截
确认服务器的Windows防火墙允许Apache程序(httpd.exe)通过80端口的入站请求,可临时关闭防火墙测试是否为拦截原因。
内容的提问来源于stack exchange,提问作者Dan Twining
相关产品推荐
相关产品推荐

