代理服务器关闭时的 Apache 反向代理错误页面

Ove*_*low 8 reverse-proxy apache-2.2

我使用 Apache2 作为 tomcat 的反向代理,我的配置类似于:

ProxyRequests Off

ProxyPass        / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
Run Code Online (Sandbox Code Playgroud)

我的问题是:我可以配置 Apache 以在 Tomcat 关闭时显示礼貌页面(“正在建设中”的 HTML 静态页面)吗?

use*_*517 13

您可以使用 Apache ErrorDocument指令来执行此操作。您应该使用 URL 指向您的 ErrorDocument 否则,如果您使用文件系统引用,您将在尝试找到它时获得额外的 503。

ErrorDocument 503 http://somehost.tld/errors/503.html
Run Code Online (Sandbox Code Playgroud)


小智 5

这是没有额外服务器或其他端口的解决方案:

ProxyPass /http_errors/ !

#Actual proxy config, must be below exception!
ProxyPass / ajp://myserver:12345/

Alias /http_errors/ /var/www/http/
ErrorDocument 503 /http_errors/503.html
Run Code Online (Sandbox Code Playgroud)

简而言之:

  1. 为某些别名添加代理异常,例如 http_errors(必须放在实际代理规则之前)
  2. 将别名映射到真实路径(必须存在并且可以被 Apache 访问)
  3. 将给定的 HTTP 状态代码映射到别名中的某个文件

所以对于上面的设置,出现问题时显示的文件是/var/www/http/503.html。