4

我尝试了在 apache 文档中找到的所有内容以及在 stackoverflow 和博客中找到的其他建议。当我将以下行添加到任何配置文件(如/etc/apache2/apache2.confor/etc/apache2/conf.d/localized-error-pages/etc/apache2/httpd.confor )时/etc/apache2/sites-enabled/000-default

ErrorDocument 503 "This is an error msg"甚至是 html 消息 ErrorDocument 503 "<h1> This is an error message </h1> 或外部 url 重定向ErrorDocument 503 http://www.google.com它都有效。

但是当我尝试像这样的内部重定向ErrorDocument 503 /ERROR_503.html 或者ErrorDocument 503 /error/ERROR_503.html我得到最后一行的默认消息时:

此外,在尝试使用 ErrorDocument 处理请求时遇到 503 Service Temporarily Unavailable 错误。

我试图将 html 错误页面放在 DocumentRootvar/wwwvar/www/error. 尝试取消注释所有/etc/apache2/conf.d/localized-error-pages将所有错误设置为具有国际化的自定义页面的文件/usr/share/apache2/error。由于此文件中的消息与默认值相同,因此该行

此外,在尝试使用 ErrorDocument 处理请求时遇到 503 Service Temporarily Unavailable 错误。不再显示。但是如果我换行

`ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var`

将localized-error-pages 文件中的新html 放置在同一页面上,错误又回来了,并且该页面未显示。如果我编辑文件HTTP_SERVICE_UNAVAILABLE.html.var,浏览器消息也没有任何变化。

更多信息:我使用 apache2 只是通过工作人员将端口 80 上的所有请求重定向到端口 8089 上的 tomcat。我的配置文件是https://dl.dropboxusercontent.com/u/1105054/apache.zip

4

3 回答 3

6

这花了我太长时间(部分是由于拼写),但我想我会发布我的整个虚拟主机文件,因为它可能有用。

您需要确保已指定 DocumentRoot,并ProxyPass /file.html !在 main 之前执行ProxyPass /

<VirtualHost *:443>
    DocumentRoot /var/www/html
    #ProxyPreserveHost On

    <IfModule env_module>
         # Fake SSL if Loadbalancer does SSL-Offload 
         SetEnvIf Front-End-Https "^on$" HTTPS=on
    </IfModule>

    SSLEngine on
    SSLCertificateFile file
    SSLCertificateKeyFile file
    SSLCertificateChainFile file

    ProxyPass /maintenance-message.html !
    ProxyPass /maintance-message_files !
    ProxyPass / "ajp://localhost:8009/"
    ProxyPassReverse / "ajp://localhost:8009/"
    ServerName server.something.com:443
    ErrorDocument 503 /maintenance-message.html
</VirtualHost>
于 2016-03-31T18:58:38.777 回答
4

就我而言,我刚刚将此ProxyPass行添加到我的虚拟服务器配置中:

ProxyPass /serverError.html !
ErrorDocument 503 /serverError.html

这告诉代理去 DocumentRoot 并搜索错误页面。

您也可能会发现这个答案很有用:https ://stackoverflow.com/a/13019667

于 2015-01-06T16:27:58.567 回答
1

我也遇到了同样的问题,经过深入搜索,我在这里找到了来自@Loren 的最好的(也是唯一的?)解决方案。

在主设置ProxyPass /file.html !之前ProxyPass /而不是之后设置后工作。此外,还需要 DocumentRoot。

于 2019-08-27T11:28:02.763 回答