---
title: "Apache和Resin组合时间歇性出现503错误的解决方法"
author: "JetMah"
date: "2010-11-13T17:05:24Z"
tags: []
categories: ["编程语言"]
slug: "apache-resin-503"
draft: false
lastmod: "2010-11-13T17:05:24Z"
id: 810652
url: "https://jetma.iteye.com/blog/810652"
---

原文出处: [Apache和Resin组合时间歇性出现503错误的解决方法](http://www.javatang.com/archives/2010/11/13/1228487.html)  
作者: Jet Mah from [Java堂](http://www.javatang.com/)  
声明: **可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明！**

 

使用Apache和Resin进行组合时，如果Resin关闭或中断的时会出现如下的HTTP 503错误：

> Service Temporarily Unavailable  
> The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

造成这个错误的原因是因为Resin无法启动，可以单独访问resin（如8080端口）查看具体的错误。

我这里要说的是，在Resin和Apache都非常非常正常的情况下，**间歇性**的出现上述错误，也就是说不是一直有，而是偶尔出现这个错误，刷新下页面就好了。这个问题非常郁闷，后来在resin的bug报告中（见参考资料）竟然发现了解决的办法：

> The important configuration are load-balance-socket-timeout, socket-timeout, load-balance-idle-time and keepalive-timeout. The two load-balance-* configure mod\_caucho. socket-timeout and keepalive-timeout configure the Resin side.
> 
> load-balance-socket-timeout needs to be large enough to handle any server-side processing delays before the first data.
> 
> socket-timeout and keepalive-timeout need to be larger than load-balance-idle-time because they need to keep the connection open for a keepalive request.
> 
> For a diagram, see
> 
> http://caucho.com/resin/admin/load-balancing.xtp

 

也就是说，Resin在同Apache进行组合通讯的时候主要依靠四个参数：load-balance-socket-timeout, socket-timeout, load-balance-idle-time 和 keepalive-timeout，其中两个load-balance-\*参数用来设置mod\_caucho（就是与Apache组合的so文件），socket-timeout和keepalive-timeout用来设置Resin。至于参数数值的大小顺序依此是：load-balance-socket-timeout &gt; socket-timeout 和 keepalive-timeout &gt; load-balance-idle-time。上述四个参数的官方说明地址为：[http://caucho.com/resin-3.1/doc/server-tags.xtp](http://caucho.com/resin-3.1/doc/server-tags.xtp)

 

那为什么会间歇性出现503错误呢？这个是因为resin默认的socket-timeout为65s，时间太短了，有些比较大的请求在这个时间之内还没有进行完。综合上面所说，参考的配置如下：

01. &lt;resin ...&gt;
02. &lt;cluster id="app-tier"&gt;
03. &lt;server-default&gt;
04. &lt;socket-timeout&gt;180s&lt;/socket-timeout&gt;
05. &lt;keepalive-max&gt;3000&lt;/keepalive-max&gt;
06. &lt;keepalive-timeout&gt;180s&lt;/keepalive-timeout&gt;
07. &lt;load-balance-idle-time&gt;120s&lt;/load-balance-idle-time&gt;
08. &lt;/server-default&gt;
09. &lt;/cluster&gt;
10. &lt;/resin&gt;

从此，这个世界清净了。

 

参考资料：  
[Apache 2.2.x + Resin 3.1.x: frequent 503 status error messages (Service Temporarily Unavailable)](http://bugs.caucho.com/view.php?id=2715)  
[0002862: Apache + Resin and 503 HTTP Error](http://bugs.caucho.com/view.php?id=2862)  
[resin apache问题](http://aiter.iteye.com/blog/391456)