11

I have an Apache web server in front of another application server, using Proxy Pass. When the request to application returned error 404, I want to show custom error page from the web server not the one that come from application server. I have tried to setup the ErrorDocument 404 on the virtual host, but it doesn't work. How should I do this? Or this is not possible?

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

  ErrorDocument 404 /error.html
</VirtualHost>
hendry.fu
  • 225
  • 1
  • 2
  • 7

1 Answers1

17

You can avoid proxying for a specific directory by specifying a ! in place of the proxy target. Since it acts on a directory, move error.html into a subdirectory (we'll say errors), and:

<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>
Shane Madden
  • 112,982
  • 12
  • 174
  • 248
  • Sorry, maybe the config lack some details, but what I want is to catch the error 404 returned from the proxy pass and show the error.html instead. – hendry.fu Aug 17 '11 at 05:33
  • 1
    Thanks, I found the way to override, I can just use the ProxyErrorOverride directive – hendry.fu Aug 17 '11 at 08:32
  • @satyavirya Good catch, I'll add that to the answer for future searchers. – Shane Madden Aug 17 '11 at 15:23
  • thanks for the hint to ProxyErrorOverride, but i found that there is a bug when using Apache 2.4 before 2.4.11 which should already be fixed: https://bz.apache.org/bugzilla/show_bug.cgi?id=53420 ... maybe the only workaround would be to reduce the proxytimeout?! – FibreFoX Apr 17 '15 at 10:50
  • ```ProxyPass /errors !``` really helped me out! – NullIsNot0 Oct 16 '19 at 18:57