I have Tomcat7 installed on an AWS EC2 machine running Ubuntu 16.04. I start Tomcat7 on port 8080, and, from that same machine, can telnet to localhost 8080, execute "GET /", and see the index page.
However, when I telnet to it from a different machine, a connection is made, I can execute "GET /", but then the connection closes with no response. I know that it is connecting to the same server and service because I can find it on the server with netstat -an.
If I execute an invalid command, eg, "XYZZY /", I get the Tomcat error page, and an entry in the logs. But valid commands do not return any response, and do not show up in the logs.
Things I have done previous to posting here:
- Use netstat -an to ensure that the connection is happening as I expect.
- Move to port 8085 to ensure that it is not some conflict with the port.
- Apply the setenv.sh settings to force IPv4 as suggested here (https://askubuntu.com/questions/567093/tomcat7-is-listening-port-but-not-processes-requests)
- Apply the setenv.sh settings to use urandom suggested here (Tomcat7 hangs on deploying apps)
So how do I get Tomcat7 to start returning responses to the remote client?
server.xml (this was original 8080, but I changed it to test if it was a port conflict):
<Connector port="8085" protocol="HTTP/1.1" connectionTimeout="20000" URIEncoding="UTF-8" />
setenv.sh (based off of responses from previous questions that sounded vaguely similar; forces urandom for entropy, and IPv4 addresses):
JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true -Djava.security.egd=file:/dev/./urandom"
Local test:
xxx@xxx:~$ sudo /etc/init.d/tomcat7 restart
[ ok ] Restarting tomcat7 (via systemctl): tomcat7.service.
xxx@xxx:~$ telnet xxx 8085
Trying xxx...
Connected to xxx.
Escape character is '^]'.
GET /
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Apache Tomcat</title>
</head>
<body>
<h1>It works !</h1>
<snipped for brevity>
</body>
</html>
Connection closed by foreign host.
Remote test:
$ telnet xxx 8085
Trying xxx...
Connected to xxx.
Escape character is '^]'.
GET /
Connection closed by foreign host.
If instead of GET /, I issue XYZZY /:
$ telnet xxx 8085
Trying xxx...
Connected to xxx.
Escape character is '^]'.
XYZZY /
<html><head><title>Apache Tomcat/7.0.68 (Ubuntu) - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 501 - Method XYZZY is not implemented by this servlet for this URI</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>Method XYZZY is not implemented by this servlet for this URI</u></p><p><b>description</b> <u>The server does not support the functionality needed to fulfill this request.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.68 (Ubuntu)</h3></body></html>Connection closed by foreign host.
So again I know that I am connecting to Tomcat.
If I do connect remotely but do not immediately issue a command, but instead on the local machine execute netstat -an | grep 8085, I get:
xxx:~$ netstat -an | grep 8085
tcp 0 0 0.0.0.0:8085 0.0.0.0:* LISTEN
tcp 0 0 xxx:8085 yyy:52329 ESTABLISHED
Where yyy is my remote address, so I know that the connection is occurring correctly.