1- 访问 www 和子文件夹:
通常,如果您想从同一 LAN 上的另一台计算机访问您的 Web 服务器,您会收到以下错误:
http://192.168.13.188/
Forbidden
You don't have permission to access / on this server.
Apache/2.4.33 (Win64) PHP/5.6.35 Server at 192.168.13.188 Port 80
(192.168.13.188是运行WAMP服务器的电脑IP)
同样,www 根目录的子文件夹也会发生同样的情况:
http://192.168.13.188/wp/
Forbidden
You don't have permission to access /wp/ on this server.
Apache/2.4.33 (Win64) PHP/5.6.35 Server at 192.168.13.188 Port 80
这个问题可以简单地通过编辑“httpd-vhosts.conf”文件来解决:
点击 WAMP 图标 > Apache > 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 local
Require ip 192.168.13
</Directory>
</VirtualHost>
您必须添加“需要 ip 192.168.13”。请注意,192.168.13 是您 LAN 的子网。这将允许 LAN 中的所有计算机访问您的 Web 服务器。
不要忘记重新启动 Apache 服务。否则更改将不会生效。
你也可以更具体:
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
Require ip 192.168.13.207
Require ip 192.168.13.20
</Directory>
</VirtualHost>
这将只允许 IP 地址为 192.168.13.207 和 192.168.13.20 的计算机。
2- 访问 phpmyadmin:
即使在授予对 LAN 计算机的访问权限后,他们也无法访问 phpmyadmin,因为它已在 phpmyadmin 的别名配置中被明确阻止。因此,我们必须编辑配置文件如下:
点击 WAMP 图标 > Apache > 别名目录 > http://localhost/phpmyadmin/ > 编辑别名
Alias /phpmyadmin "c:/wamp64/apps/phpmyadmin4.7.9/"
<Directory "c:/wamp64/apps/phpmyadmin4.7.9/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride all
<ifDefine APACHE24>
Require local
Require ip 192.168.13
</ifDefine>
<ifDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from localhost ::1 127.0.0.1
Allow from 192.168.13
</ifDefine>
# To import big file you can increase values
php_admin_value upload_max_filesize 128M
php_admin_value post_max_size 128M
php_admin_value max_execution_time 360
php_admin_value max_input_time 360
</Directory>
您必须添加“需要 ip 192.168.13”和“允许来自 192.168.13”。
3- 访问 wordpress 网站:
如果您尝试访问局域网中的 wordpress 网站,则会出现另一个问题。默认情况下,wordpress 配置为将您重定向到 localhost。换句话说,如果您的目标是通过http://192.168.13.188/wordpress/ 访问您的网站,那么wordpress 往往会在http://localhost/wordpress/ 打开,这当然会导致错误,因为您的网站不在客户端计算机的本地主机上,而是在192.168.13.188!
如果您使用的是 Internet Explorer,您不会注意到此重定向,因为 IE 不会反映它,只会向您显示错误页面。但是,如果您尝试在 Chrome 或 Firefox 中打开您的网站,您会看到您被重定向到 localhost。无论如何,这个问题可以通过以下方式解决:
登录到 wordpress 管理面板 > 设置 > 常规
编辑“WordPress 地址”和“站点地址”字段。将 localhost 更改为您的 IP 地址:
WordPress 地址(URL): http://192.168.13.188/wordpress
网站地址(URL): http://192.168.13.188/wordpress
就是这样。如果您有其他建议来完成此答案,请离开 cmets。