ec2、tomcat7 和 503 错误

发布于 2024-12-08 04:25:24 字数 364 浏览 2 评论 0原文

我有 Amazon 开箱即用的 Tomcat7 实例 (ami-518e4c38),向其部署了一个 war 文件,但不断收到 503 错误。

我已将连接器设置为侦听 server.xml 中的端口 80,在默认安全组中,我将 80 (HTTP) 设置为 0.0.0.0/0

我假设我不必手动启动/停止 tomcat ,应该在实例启动时启动。我对这一点正确吗?

当我在端口 80 上 ping localhost(同时 ssh 进入实例)两次时,我得到:

2 packets transmitted, 2 received, 0% packet loss, time 999ms

任何帮助将不胜感激。

I have Amazon's out of the box instance with Tomcat7 (ami-518e4c38), deployed a war file to it, but keep getting 503 error.

I've set the connector to listen on port 80 in server.xml, in the default security group I got 80 (HTTP) set to 0.0.0.0/0

I'm assuming that I don't have to start/stop tomcat manually, should start when the instance is launched. Am I correct on this one?

When I ping localhost (while ssh'ed into the instance ) 2 times on port 80 I get:

2 packets transmitted, 2 received, 0% packet loss, time 999ms

Any help will be most appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久随 2024-12-15 04:25:24

说真的,这不是一个答案,您应该描述您最初的情况以及您在答案中所做的事情并接受它。

我只是想弄清楚发生了什么,我需要您的反馈来了解更多信息。

最初你有一个503错误,这意味着服务不可用,通常Tomcat配置在Apache后面,我的意思是Apache服务器获取(所有)请求并可能将(部分)它们转发到Tomcat(如果配置为这样做)。

如果您收到 503 错误,则意味着有某个服务器已启动并正在运行来回复您,而该服务器应该是 Apache。如果我关闭 Tomcat 并尝试请求一个将转发到 Tomcat 的 URL,我会得到:

服务暂时不可用

由于维护停机或容量问题,服务器暂时无法满足您的请求。请稍后重试。
Apache/2.2.17 (Ubuntu) 服务器位于 private.it 端口 80

这就是为什么我的第一个想法是检查 Tomcat 是否正在运行。然后你就这么做了:

$ ps fax | grep tomcat

你发现 tomcat 实际上正在运行:

1127 点/0 S+ 0:00 _ grep tomcat 987 ? Sl 0:42 /usr/lib/jvm/jre/bin/java -classpath /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat7 -Dcatalina.home=/opt/tomcat7 -Djava.awt.headless=true -Djava.endorsed.dirs=/opt/tomcat7/endorsed -Djava.io.tmpdir=/opt/tomcat7/temp -Djava.util.logging.config.file=/opt/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina.startup.Bootstrap启动

另一个原因可能是 Tomcat-Apache 连接配置不正确。然而,随后您发布了 Tomcat 尝试绑定端口 80 并失败的消息:

2011 年 9 月 30 日上午 4:07:51 org.apache.coyote.AbstractProtocol init 严重:无法初始化与 ProtocolHandler ["http-bio-80"] 关联的端点 java.net.BindException:地址已在使用中:80

I尝试复制该错误,我进入我的 conf/server.xml 文件并将连接器更改为侦听端口 80 而不是8080:

<!-- A "Connector" represents an endpoint by which requests are received
     and responses are returned. Documentation at :
     Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
     Java AJP  Connector: /docs/config/ajp.html
     APR (HTTP/AJP) Connector: /docs/apr.html
     Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="80" protocol="HTTP/1.1" 
            connectionTimeout="20000" 
            redirectPort="8443" />

我启动 tomcat 并监视日志:

bin/startup.sh && tail -f logs/catalina.out 

我得到一个与您得到的类似的异常,但不完全相同:

SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-bio-80"]
java.net.BindException: Permission denied <null>:80

现在,如果我检查 Tomcat 是否正在运行,我发现它确实正在运行。虽然没有检查,但我认为在这种情况下,服务器会放弃并退出。就我而言,更正方法是,要么关闭 Apache 并直接使用 Tomcat(这对于高流量站点来说是不可取的),要么将 Tomcat 移回端口 8080 并安装 mod_jk。

mod_jk的安装可以实现Apache和Tomcat之间的通信。然后,在虚拟主机配置中,我将安装一个文件夹或根文件夹,并在必要时进行一些 URL 重写:

JkMount /webappname/* ajp13_worker
RewriteEngine on
RewriteRule ^/nametoshow/(.*)$ /webappname/$1 [PT,QSA]

一切都应该正常。不过,我不确定你是如何解决绑定错误的,你没有说。

Seriously, this isn't an answer, you should describe your initial situation and what you did in your answer and accept it.

I just want to clear up what happened, and I would need your feedback to understand more about it.

Initially you had a 503 error, which means service unavailable, normally Tomcat is configured behind Apache, and with this I mean that the Apache server gets (all) the requests and may forward (some of) them to Tomcat, if configured to do so.

If you get a 503 error, it means there is some server up and running to reply to you and that should be Apache. If I shut down Tomcat and try to request an URL that would be forwarded to Tomcat I get:

Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
Apache/2.2.17 (Ubuntu) Server at private.it Port 80

That's why my first thought was to check if Tomcat was running. Then you did:

$ ps fax | grep tomcat

And you got that tomcat was actually running:

1127 pts/0 S+ 0:00 _ grep tomcat 987 ? Sl 0:42 /usr/lib/jvm/jre/bin/java -classpath /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat7 -Dcatalina.home=/opt/tomcat7 -Djava.awt.headless=true -Djava.endorsed.dirs=/opt/tomcat7/endorsed -Djava.io.tmpdir=/opt/tomcat7/temp -Djava.util.logging.config.file=/opt/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina.startup.Bootstrap start

Another reason could be that the connection Tomcat-Apache is not configured correctly. However then you posted that Tomcat was trying to bind port 80 and failing:

Sep 30, 2011 4:07:51 AM org.apache.coyote.AbstractProtocol init SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-bio-80"] java.net.BindException: Address already in use :80

I tried to replicate that error, I went in my conf/server.xml file and change the connector to listen on port 80 instead of 8080:

<!-- A "Connector" represents an endpoint by which requests are received
     and responses are returned. Documentation at :
     Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
     Java AJP  Connector: /docs/config/ajp.html
     APR (HTTP/AJP) Connector: /docs/apr.html
     Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="80" protocol="HTTP/1.1" 
            connectionTimeout="20000" 
            redirectPort="8443" />

I start tomcat and monitor the log:

bin/startup.sh && tail -f logs/catalina.out 

And I get an exception that is similar to what you get, but not exactly the same:

SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-bio-80"]
java.net.BindException: Permission denied <null>:80

Now if I check whether Tomcat is running I find that is indeed running. While without checking I'd have supposed that in a case like that the server would have just gave up and quit. In my case the correction would be, either shut down Apache and use Tomcat directly, which is not advisable for high traffic sites or move Tomcat back to port 8080 and install mod_jk.

The installation of mod_jk enables the communication between Apache and Tomcat. Then in the virtual host configuration I'd mount a folder or the root folder and do some URL rewriting if necessary:

JkMount /webappname/* ajp13_worker
RewriteEngine on
RewriteRule ^/nametoshow/(.*)$ /webappname/$1 [PT,QSA]

And everything should work. However, I am not sure how you solved the bind error, you didn't say.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文