user3100209
user3100209

Reputation: 367

Tomcat server not working "externally"

I have my tomcat server set up and it works on LOCAL-HOST, however I can't run it externally. Do I have to change some settings? I tried everything but it doesn't seem to work else where... It is weird because it works perfectly fine on local host.

Upvotes: 1

Views: 14829

Answers (1)

stringy05
stringy05

Reputation: 7067

So you are running tomcat within a spring boot app, started from the maven spring boot plugin and it listens on localhost but can't be reached using your LAN IP address.

Just a note - people on SO are keen to help but it shouldn't be a treasure hunt to get the necessary information.

First

Check which IP address and port tomcat is listening on: the spring boot log will usually tell you the name of the host, eg mymac.local, and the port will be shown, port(s): 8080 (http), :

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.2.3.RELEASE)


2015-04-29 09:14:33.269  INFO 7031 --- [main] hello.Application  Starting Application v0.1.0 on mymac.local with PID 7031 (/Users/foo/Development/java/springframework/gs-spring-boot/complete/target/gs-spring-boot-0.1.0.jar started by foo in /Users/foo/Development/java/springframework/gs-spring-boot/complete)
2015-04-29 09:14:35.072  INFO 7031 --- [main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2015-04-29 09:14:35.506  INFO 7031 --- [main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2015-04-29 09:14:35.507  INFO 7031 --- [main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.20

And as a rule tomcat starts listening on all IP addresses (0.0.0.0) so it's odd this doesn't work for you.

Another way to do this is with netstat. For Max/Linux:

$ netstat -an  | grep 8080
tcp46      0      0  *.8080                 *.*                    LISTEN     

On windows

C:\> netstat -an | find "8080"    
  TCP    0.0.0.0:8080            0.0.0.0:0              LISTENING
  TCP    [::]:8080               [::]:0                 LISTENING

If your app is listening on 0.0.0.0 or a real IP like 192.168.0.100 or something then you are likely getting firewalled or blocked on the network somehow.

If your app is listening only on localhost/127.0.0.1 then you need to tell tomcat to use the real IP, like this question: How to configure embedded Tomcat integrated with Spring to listen requests to IP address, besides localhost?

Secondly Do a basic connectivity with a simple client like curl/telnet/netcat. Browsers, especially IE, may be subject to restrictions like Windows Group Policy, that will prevent many things working with little or no information.

So on a different machine, see if you can telnet to the tomcat port (assuming tomcat is running on 192.168.0.100):

$ telnet 192.168.0.100 8080
Trying 192.168.0.100...
Connected to localhost.
Escape character is '^]'.

If you see the Connected message then you have connectivity, so if it's not working from the browser then there is something else wrong.

If it is refused right away then there is no route / connection between the 2 computers. This usually means your tomcat is not listening on the correct IP address

$ telnet 192.168.0.100 8080
Trying  192.168.0.100...
telnet: connect to address  192.168.0.100: Connection refused
telnet: Unable to connect to remote host

If it just hangs on the connecting message then it's probably a firewall.

$ telnet 192.168.0.100 8080
Trying 192.168.0.100...

Upvotes: 17

Related Questions