Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
572 views
in Technique[技术] by (71.8m points)

wamp - WAMPServer, access server from mobile phone

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 virtual host on another device

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?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

What the actual problem is

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.

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

But you cannot do that on a phone/tablet.

What Apache expects to be able to asssociate a request to a Vhost

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.

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.

The simplest way to get round this is:

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

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.

So how do we do this

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

WAMPServer 3: Do this using the menus, not by doing a manual edit on 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

Suggested httpd-vhosts.conf file

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

Restart Apache from wampmanager after completing these edits.

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 will find the correct code to serve from both requests.

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...