1

I have an Apache server that has / forwarding to a Tomcat server. When the Tomcat server is down, I want to display an error message. Here's what I have currently:

ErrorDocument 502 "We're down, sorry :("

I would like to show a relatively rich document (funny picture and stuffs), not just a one sentence message. The issue is, it doesn't appear I can serve documents, only redirect to them. I'm looking at this documentation.

I'd like to keep the same URL, but serve a different HTML file. Any way to do this?

<VirtualHost *:443>
        ServerName ${DOMAIN_NAME}
        ProxyRequests Off

        ProxyAddHeaders On

        ProxyPass /stomp http://tomcat:8080/stomp
        ProxyPassReverse /stomp http://tomcat:8080/stomp

        ProxyPass /.well-known http://mail.${DOMAIN_NAME}:80/.well-known
        ProxyPassReverse /.well-known http://mail.${DOMAIN_NAME}:80/.well-known

        ProxyPassMatch / http://tomcat:8080 retry=0 timeout=10
        ProxyPassReverse / http://tomcat:8080

        SSLCertificateFile /etc/letsencrypt/live/${DOMAIN_NAME}/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/${DOMAIN_NAME}/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

        ErrorDocument 502 ${PROXY_ERROR_MESSAGE}
        ErrorDocument 503 ${PROXY_ERROR_MESSAGE}
</VirtualHost>
Chris Smith
  • 205
  • 2
  • 10
  • What do you mean with "forwarding"? Is your tomcat on another server, another domain? How does your config look like? – Broco Sep 24 '16 at 01:00
  • @Broco I mean "proxying". Tomcat is on the same server, but exposed through another port. – Chris Smith Sep 24 '16 at 01:10
  • @Broco See my edit for the config. – Chris Smith Sep 24 '16 at 01:39
  • I didn't dig so much yet about your specific problem, but Apache is fully able to manage custom error pages, e.g : `ErrorDocument 404 http://error.example.com/not_found.html`. From there the target html page is fully able to display any funny pictures and stuff... – krisFR Sep 24 '16 at 01:43
  • This redirects though, I want it to serve the file, without redirecting. – Chris Smith Sep 24 '16 at 01:46
  • Redirecting what ? there is no redirect either in my example nor in your actual settings. Please clarify what you consider as a "redirect". – krisFR Sep 24 '16 at 01:53
  • If I set the error document to `http://domain.com/error` (and turn off Tomact), then go to my domain, it will wait a few seconds and say it's not redirecting properly (with the url `domain.com/error`). If I set the error document to say, `http://google.com`, it redirects me to Google when Tomcat isn't running. I think this is pretty strong indication of a redirect. – Chris Smith Sep 24 '16 at 01:56
  • By "redirect", I mean it's like you click a link. You are no longer on the previous page. This is undesired because the user can't just reload the page to see if Tomcat is back up, he has to hit the back button. – Chris Smith Sep 24 '16 at 02:03
  • You may setup `ProxyPass` correctly to handle your error message without proxying it : http://serverfault.com/questions/357276/errordocument-when-using-apache-as-reverse-proxy ? – krisFR Sep 24 '16 at 02:08
  • @krisFR Although that doesn't solve my question in general, it does solve the problem in my specific circumstance. Thanks! – Chris Smith Sep 24 '16 at 02:17

1 Answers1

2

If you specific a fully qualified URL for an error document you are implicitly causing a redirect because the browser must be told to "go get the error page somewhere else". However if you do something like:

ErrorDocument /errors/my503.html

The there will be no redirect as long as that URI path is served directly in apache. In your setup because you are proxying '/', you must explicity exclude that document from being proxied back to tomcat like this:

ProxyPass /errors/my503.html !
ErrorDocument /errors/my503.html

You also need to add exclusions for any page components used in the HTML.

If you want to serve custom error pages from actual HTTP error codes that come from tomcat (4xx codes normally), then you should look at the ProxyErrorOverride directive

Unbeliever
  • 2,336
  • 1
  • 10
  • 19