我在运行Ubuntu 16.04的AWS EC2机器上安装了Tomcat7。 我在端口8080上启动Tomcat7,并从同一台机器上telnet到本地主机8080,执行“GET /”并查看索引页面。
但是,当我从另一台机器telnet到它时,build立连接,我可以执行“GET /”,但是连接closures,没有响应。 我知道它连接到相同的服务器和服务,因为我可以在服务器上用netstat -anfind它。
如果我执行了一个无效的命令,例如“XYZZY /”,我得到了Tomcat的错误页面,并在日志中logging了一个条目。 但有效的命令不会返回任何响应,也不会显示在日志中。
之前我已经做过的事情发布在这里:
那么如何让Tomcat7开始向远程客户端返回响应呢?
server.xml(这是原始的8080,但我改变它来testing是否是端口冲突):
<Connector port="8085" protocol="HTTP/1.1" connectionTimeout="20000" URIEncoding="UTF-8" />
setenv.sh(根据以前听起来模糊的相似的问题的回答;强制使用熵和IPv4地址):
JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true -Djava.security.egd=file:/dev/./urandom"
本地testing:
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.
远程testing:
$ telnet xxx 8085 Trying xxx... Connected to xxx. Escape character is '^]'. GET / Connection closed by foreign host.
如果不是GET /,我发出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.
所以我再次知道我正在连接到Tomcat。
如果我远程连接但不立即发出命令,而是在本地机器上执行netstat -an | grep 8085,我得到:
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
在哪里yyy是我的远程地址,所以我知道连接正在发生。
令人失望的是,这个问题是一个防火墙进行端口validation,从而终止请求。 所以任何以“GET”开头的东西都被阻止出去,这就是为什么我看到了我所做的结果。 将其更改为80端口,突然一切正常。