Service Temporarily Unavailable: Apache和Resin组合时间歇性出现503错误的解决方法

使用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 > socket-timeout 和 keepalive-timeout > load-balance-idle-time。上述四个参数的官方说明地址为:http://caucho.com/resin-3.1/doc/server-tags.xtp

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

    <resin ...>
        <cluster id="app-tier">
            <server-default>
                <socket-timeout>180s</socket-timeout>
                <keepalive-max>3000</keepalive-max>
                <keepalive-timeout>180s</keepalive-timeout>
                <load-balance-idle-time>120s</load-balance-idle-time>
            </server-default>
        </cluster>
    </resin>

从此,这个世界清净了。

参考资料:
Apache 2.2.x + Resin 3.1.x: frequent 503 status error messages (Service Temporarily Unavailable)
0002862: Apache + Resin and 503 HTTP Error
resin apache问题
Related Posts:

    Ext中设置Ajax超时时间
    PHP中出现“Unable to load dynamic library”问题的解决方法
    Resin中对日志输出的配置
    Apache+Resin下如何写伪静态和301跳转
    Apache和Resin组合时UrlRewriteFilter失效的解决方法

你可能感兴趣的:(available)