Apache Httpd 自定义 ErrorDocument 404 当 ProxyPass 返回 404 时

hen*_*.fu 10 mod-proxy errordocument apache-2.2

我在另一个应用程序服务器前面有一个 Apache Web 服务器,使用 Proxy Pass。当对应用程序的请求返回错误 404 时,我想显示来自 Web 服务器的自定义错误页面,而不是来自应用程序服务器的页面。我试图在虚拟主机上设置 ErrorDocument 404,但它不起作用。我该怎么做?或者这是不可能的?

<VirtualHost *:80>
  ServerName servername
  DocumentRoot /somepath/
  ProxyPass / http://localhost:8080/someapp/
  ProxyPassReverse / http://localhost:8080/someapp/

  ErrorDocument 404 /error.html
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

Sha*_*den 15

您可以通过指定 a!代替代理目标来避免对特定目录进行代理。因为它作用于一个目录,所以移到error.html一个子目录(我们会说errors),然后:

<VirtualHost *:80>
  ServerName servername
  DocumentRoot /somepath/
  ProxyPass /errors !
  ProxyPass / http://localhost:8080/someapp/
  ProxyPassReverse / http://localhost:8080/someapp/
  ProxyErrorOverride On
  ErrorDocument 404 /errors/error.html
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)