【问题标题】:Redirect tomcat to maintenance page when down关闭时将tomcat重定向到维护页面
【发布时间】:2011-06-03 07:58:53
【问题描述】:

我在 ubuntu9.10 和 8.10 服务器上使用带有 mod_jk 设置(都在端口 80 上运行)的 tomcat6。我在 /usr/share/tomcat/webapps 下部署战争文件。部署过程中,重启tomcat,在浏览器访问tomcat应用时会出现如下页面:

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.11 (Ubuntu) mod_jk/1.2.15 Server at 192.168.2.54 Port 80

当 tomcat 服务器关闭时,我如何将此页面重定向到其他一些自行创建的维护页面?。

【问题讨论】:

    标签: tomcat redirect apache2


    【解决方案1】:

    如果您使用 mod_jk 和 tomcat 连接器,这是预期的行为。如果你使用类似的东西

    ErrorDocument 503 "foo"
    

    您将在页面上看到“foo”或

    ErrorDocument 503 "http://www.somedomain.com"
    

    这将引导您成功访问 somedomain.com。但是如果你使用类似的东西

    ErrorDocument 503 /maintenance.html
    

    Apache 将无法找到 [DocumentRoot]/maintenance.html,因为它正在 tomcat 连接器的上下文中查找。您需要卸载连接器并告诉 Apache 从另一个位置提供静态内容。

    这是帮助您开始使用 mod_jk 的好指南。 Custom Error Pages with Apache and Tomcat Connectors

    编辑:这是我用来让我们的自定义 503 页面正确呈现的解决方案。

    首先,我们所有的自定义错误页面都以错误代码为前缀,因为我们的网络应用程序可能不包含以这些状态代码作为文件名根的文件。 因此,对于使用您的示例,我将在名为“custom_errors”的目录中包含以下三个文件:

    /503_maintenance.html
    /503_maintenance.css
    /503_corp_logo.png
    

    这使得从 jk 挂载中排除与自定义错误页面相关的任何文件变得容易。在我们的 vhost 文件中,然后我们设置错误文档位置和别名

    #Alias the location of your custom error page files
    Alias           /error/ /var/apache2/2.2/htdocs/custom_errors
    ErrorDocument   503     /error/503_maintenance.html
    
    #mount the core tomcat application
    JkMount     /*      myWorker
    
    #set the 503 code if myWorker is unavailable 
    #and exclude the 503 pages from the tomcat/jboss application
    JkMount     /*      myWorker;use_server_errors=503
    JkUnMount   /503*   myWorker
    

    这基本上告诉 Apache 和 mod_jk 不要在 tomcat 连接器的上下文中挂载任何带有 503 前缀的文件,而是在本地查找这些文件。如果你不想使用相对于 DocumentRoot 的位置,你可以像我一样使用和 Alias。

    【讨论】:

    • 很棒的回复,但它对我不起作用...我必须更改两件事 1. 在“别名”行中添加斜杠 2. 卸载 /error* 而不是 /503*
    • 嗨 Andrij:你能检查一下这个问题吗,它很相似。我不介意使用网页进行维护,但我不知道应该将它们放在哪里才能使配置工作,请查看此链接:serverfault.com/questions/741494/…
    • 这真的很有帮助。我能够将它与shellhacks.com/redirect-site-maintenance-page-apache-htaccess 结合起来,将 IP 地址列入白名单,以便在我们处于维护窗口期间访问 tomcat 应用程序
    【解决方案2】:

    您可以在 Apache 中为错误代码 503 设置自定义错误页面。

    http://httpd.apache.org/docs/2.2/mod/core.html#errordocument

    ErrorDocument 503 /maintance.html
    

    【讨论】:

    • 是的,它在一台机器上工作。但在另一台机器上,它正在重定向,但不显示维护页面。当我检查停止 tomcat 时,它在 Web 浏览器上显示“maintenance.html”而不是维护页面。这里有什么技巧或窍门吗?
    猜你喜欢
    • 2011-12-07
    • 2021-09-14
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 1970-01-01
    • 2017-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多