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?
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}
Answer
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
No comments:
Post a Comment