本文介绍了WAMPServer,通过手机访问服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我用一些唯一的URL设置了一些虚拟主机,它们在桌面上可以正常工作.但是,当我连接网络上的移动设备时,它似乎无法正确访问任何东西,但只能访问默认的localhost虚拟主机,而这仅是它是我拥有的唯一虚拟主机.

So I set up a few virtual hosts with unique urls and they work just fine on the desktop. However, when I connect a mobile device on the network, it can't seem to access anything properly but the default localhost virtualhost and that's only when it's the only virtualhost I have up.

除了网站标题不同之外,我的设置和编码几乎都是这样

My setup and coding is pretty much this except with a different site title

在另一台设备上破坏服务器3.0虚拟主机

,尽管该解决方案将我重定向到我的唯一网址,但默认的wordpress网站上缺少图片.

and while that solution redirects me to my unique url, it has a lack of images on a default wordpress website.

是否有人设法使移动设备完全访问本地主机以外的链接?

Has anyone managed to get mobile devices fully accessing links other than on localhost?

推荐答案

自从我发布了您引用的答案以来,我就决定了一个更简单的解决方案.

Since I posted the answer you referenced, I have decided upon a simpler solution.

因为我们无法像PC那样摆弄手机的配置,所以手机永远无法在服务器计算机上的虚拟主机定义中找到我们创建的域名,因为该域名在任何DNS服务器中都不存在它可以找到IP地址,并且DNS服务器是电话可以查看的唯一位置,除非它已越狱.

Because we cannot fiddle with the configuration of a phone like we can with a PC, the phone can never find the domain name we create in our Virtual Host definition on the Server machine, because it does not exist in any DNS Server for it to locate the IP Address in, and a DNS Server is the only place a phone can look, unless it is jail broke.

如果要从另一台PC访问虚拟主机域之一,则可以将这样的行添加到另一台PC的HOSTS文件中.

If you wanted to access one of your Virtual Hosts domains from another PC you could just add a line like this into the HOSTS file on the other PC like this.

192.168.0.10 example.local

但是您不能在手机/平板电脑上这样做.

创建Apache虚拟主机时,实际上是在告诉Apache查看传入连接上的域名,并将该域名与多个虚拟主机定义之一中存在的ServerName匹配.

When we create an Apache Virtual Host, we are actually telling Apache to look at the domain name on the incoming connection and match that domain name to a ServerName that exists in one of our multiple Virtual Hosts definitions.

但是,如果在尝试通过电话连接到我们的虚拟主机域时,例如使用example.lccal作为虚拟主机域,则该电话将进行DNS查找,并且找不到该域,因此无法获取其IP地址.

But if we use for example example.lccal as our virtually hosted domain when we attempt to connect to that from our phone, the phone does a DNS Lookup and does not find that domain and therefore cannot get its ip address.

假设我们无权将记录添加到DNS服务器,我们必须提出另一种解决方案.

Assuming we do not have access to adding record to a DNS Server we have to come up with a different solution.

其中最简单的方法是使用运行WAMPServer(Apache)服务器的PC的IP地址和特定的端口号.因此,这是我们要通过电话使用的每个站点的不同端口号.

The simplest of these is to use the IP Address of the PC running the WAMPServer(Apache) server and a specific port number. So thats a different port number for each of our sites we want to use from a phone.

像在现有的2条Listen语句之后一样,将新的侦听端口添加到httpd.conf

Add the new listening port to httpd.conf like so after the 2 existing Listen statements

#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.

Restart Apache from wampmanager after completing these edits.

现在,您可以使用ServerNameexample.dev在WAMPServer PC上进行测试,并使用端口号即192.168.0.10:8000

Now you test this from the WAMPServer PC by using the ServerName i.e example.dev and from the phone using the ip of the PC running WAMPServer with the port number i.e. 192.168.0.10:8000

Apache将从这两个请求中找到可以使用的正确代码.

Apache will find the correct code to serve from both requests.

如果您希望通过电话访问多个虚拟主机,则只需复制此想法并更改每个新站点的端口号,就可以使用8001,8002,8003等.想要访问.

If you want more than one Virtual Host to be accessible from your phone you just duplicate this idea and change the port number for each new site, lets say you would use 8001,8002,8003 etc. For as many sites as you want to access.

这篇关于WAMPServer,通过手机访问服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 14:30