WAMPServer,手机访问服务器 [英] WAMPServer, access server from mobile phone

查看:51
本文介绍了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

另一台设备上的 wamp server 3.0 虚拟主机

虽然该解决方案将我重定向到我的唯一 url,但它在默认的 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.local 作为我们的虚拟托管域,则手机会执行 DNS 查找并找不到该域,因此无法获取它的IP地址.

But if we use for example example.local 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.

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

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

WAMPServer 3:使用菜单执行此操作,而不是通过对 httpd.conf

right click wampmanager-> Tools -> Add listen port for Apache


#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 和手机使用运行 WAMPServer 的 PC 的 IP 进行测试,端口号为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.

您可能还需要修改防火墙以允许在端口 8000 或您选择使用的任何端口上访问 http

You may also have to amend your firewall to allow access on http on port 8000, or whatever port you pick to use

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆