所以我设置了几个带有唯一网址的虚拟主机,它们在桌面上运行得很好。但是,当我在网络上连接移动设备时,它似乎无法正常访问任何东西,而是默认的localhost虚拟主机,而且只有当它是我唯一拥有的虚拟主机时。
除了不同的网站标题
之外,我的设置和编码几乎都是这样wamp server 3.0 virtual host on another device
虽然该解决方案将我重定向到我的唯一网址,但它在默认的wordpress网站上缺少图像。
有没有人设法让移动设备完全访问localhost以外的链接?
答案 0 :(得分:5)
由于我发布了您引用的答案,我已经决定了一个更简单的解决方案。
因为我们无法像使用PC那样摆弄手机的配置,手机永远无法找到我们在服务器计算机上的虚拟主机定义中创建的域名,因为它在任何DNS服务器中都不存在它可以找到IP地址,而DNS服务器是手机可以看到的唯一地方,除非它被监禁。
如果您想从另一台PC访问其中一个虚拟主机域,您只需将这样的行添加到另一台PC上的HOSTS文件中即可。
192.168.0.10 example.local
但你不能在手机/平板电脑上做到这一点。
当我们创建Apache虚拟主机时,我们实际上是在告诉Apache查看传入连接上的域名,并将该域名与我们多个虚拟主机定义之一中存在的ServerName
进行匹配。 / p>
但是,如果我们在尝试从手机连接时使用example.lccal
作为我们的虚拟托管域,则手机会进行DNS查找并且找不到该域,因此无法获取其IP地址。
假设我们无权将记录添加到DNS服务器,我们必须提出不同的解决方案。
最简单的方法是使用运行WAMPServer(Apache)服务器的PC的IP地址和特定的端口号。这就是我们希望通过手机使用的每个网站的不同端口号。
在现有的httpd.conf
个语句之后,将新的侦听端口添加到Listen
#Listen 12.34.56.78:80
Listen 0.0.0.0:80
Listen [::0]:80
Listen 0.0.0.0:8000
Listen [::0]:8000
建议的httpd-vhosts.conf
档案
#
# Virtual Hosts
#
# Always keep localhost, and always first in the list
# this way a ramdom look at your IP address from an external IP
# maybe a hack, will get told access denied
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp/www
<Directory "c:/wamp/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
# The normal Vhost definition for one of our sites
<VirtualHost *:80>
ServerName example.local
DocumentRoot "c:/websrc/example/www"
<Directory "d:/websrc/example/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
# Access example.dev from phone for testing
<VirtualHost *:8000>
ServerName example.local
DocumentRoot "c:/websrc/example/www"
<Directory "d:/websrc/example/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
# assuming yoursubnet is 192.168.0.?
# allow any ip on your WIFI access
Require ip 192.168.0
</Directory>
</VirtualHost>
完成这些编辑后,从wampmanager重启Apache。
现在,您可以使用ServerName
example.dev
从WAMPServer PC进行测试,然后使用运行WAMPServer的PC的IP从手机上测试,端口号为192.168.0.10:8000
Apache将从两个请求中找到正确的代码。
如果您希望从手机访问多个虚拟主机,您只需复制此想法并更改每个新站点的端口号,假设您将使用8001,8002,8003等。对于您的多个站点想要访问。
答案 1 :(得分:0)
我得到你没有权限禁止访问此服务器上的/
hosts file : 192.168.1.2 example.local
httpd.conf file:
Listen 0.0.0.0:8081
Listen [::0]:8081
Listen 192.168.1.2:8082
vhosts file:
# Virtual Hosts
#
<VirtualHost *:8081>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:8082>
ServerName example.local
DocumentRoot "c:/wamp64/www/goodmorning"
<Directory "c:/wamp64/www/goodmorning/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
Require ip 192.168.1.2
</Directory>
</VirtualHost>
有什么建议吗? Wampp 3.1.9 64bit