因为做网页经常需要测试手机浏览模式,有时候用 Chrome 模拟手机测试的好好的,但是切到手机上再测试的时候就会出现问题。因为用 WAMP 本地测试,发现竟然无法用 192.168.0.xxx 访问本机。网上查了一下,原来 WampServer 禁用了全网访问,只开放了本地访问。如果想改变全局访问的话,需要更改一些 WampServer 的配置。

当用手机访问的时候,会出现 403 Forbidden 错误

WAMP 如何设置局域网访问方法

1. 打开 wamp64\bin\apache\apache2.4.27\conf\extra\httpd-vhosts.conf

找到

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/www"
  <Directory "${INSTALL_DIR}/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
  </Directory>
</VirtualHost>

然后修改为

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/www"
  <Directory "${INSTALL_DIR}/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

2. 重启 WAMP 即可。