1

I want to be able to test my webpage on a mobile phone. I was using an Apache 2.2 server to host my web page locally. In this case, I connected my development machine and my phone to the same WiFi. I then accessed my localhost on my phone via the machine's external IP address.

Now, I need a servlet so I am switching my application to run on a Tomcat v7 server. I am now unable to access my localhost via external IP address on my phone. I have tested the IP address on my development machine browser to make sure it is correct. I am trying to access port 80 on both the Apache 2.2 server and the Tomcat server.

I have checked my firewall settings, but I am assuming since port 80 works when I run my Apache 2.2 server, it should also work when I run the Tomcat server?

This is my Tomcat Connector String:

<Connector port="80" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

Solutions I've tried: I restarted my Tomcat server after each of the following and I still cannot access my localhost

1) add the following to my connector string as posted here: https://stackoverflow.com/a/8850066/4639035

useIPVHosts="true"

2) add a inbound rule in my firewall settings (although I think port 80 has already been allowed since it works when I use my Apache 2.2 server, but I could be wrong): http://www.mobitechie.com/android-2/how-to-access-localhost-on-android-over-wifi/

Any suggestions? Thanks!

Community
  • 1
  • 1
Yenni Tan
  • 11
  • 1
  • 3
  • there a concept called port forwarding. read about it. – Sachin Verma Apr 07 '15 at 07:55
  • thanks, I am trying to follow this tutorial: http://blog.eventloud.com/2011/04/20/how-to-setup-apache-forwarding-to-tomcat-run-tomcat-on-port-80/, but I'm not sure how to do step 4: "4. Enable proxy and proxy_http modules using these commands (on linux): a2enmod proxy a2enmod proxy_http." I am on Windows machine. I couldn't find any info on enabling using windows command line. Thanks in advance! – Yenni Tan Apr 07 '15 at 19:06
  • edit -- i'm going to try to use Cygwin – Yenni Tan Apr 07 '15 at 19:13

2 Answers2

1

`Step 1: Go to directory where tomcat is installed and look for server.xml file.Usually the path is

C:\Program Files\Apache Software Foundation\Tomcat 9.0\conf\server.xml

Open it with editor and look for connector tag.It will be like

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"/>

Add address="0.0.0.0" to it and change port to 80.

<Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               address="0.0.0.0" />

save the file.

step 2: Go to the firewall and network protection setting of the pc and turn off the public network firewall.

step 3: Start the tomcat server.Then use the local ip address of pc and port 8080 (used by tomcat server as default unless you have changed it) form other device to connect with the tomcat server on the pc.

eg - http://192.168.8.137:80/ (replace 192.168.8.137 with your pc's local ip address)

Vader
  • 159
  • 7
0

Hi EveryOne If You want to run your localhost in your mobile phone or other devices Step-1 : Connect Your current project running device and where you want to access that device with same network(wifi) or hotspot. Step-2 : Open cmd and type ipconfig Step-3 : then you will get IPv4 Address. . . . . . . . . . . : 192.168.77.84 Step-4 : Open any browser in other device and type http://192.168.77.84:8080/url Step-5 : 192.168.77.84 change this number according to your device here 8080 my localhost port number you write your port number. Thankyou