How to solve add a custom error 503 page html on ubuntu apache2 using it with mod_jk and virtual host redirecting to tomcat
Asked Answered
R

3

5

I tried all I found at apache documentation and other sugestions found at stackoverflow and blogs. When I add the folloowing line to any configuration file like /etc/apache2/apache2.conf or /etc/apache2/conf.d/localized-error-pages or /etc/apache2/httpd.conf or /etc/apache2/sites-enabled/000-default:

ErrorDocument 503 "This is an error msg" or even an html message ErrorDocument 503 "<h1> This is an error message </h1> or an external url redirect ErrorDocument 503 http://www.google.com it works.

But when I try an internal redirect like ErrorDocument 503 /ERROR_503.html or ErrorDocument 503 /error/ERROR_503.html I get the default message with last line:

Additionally, a 503 Service Temporarily Unavailable error was encountered while trying to use an ErrorDocument to handle the request.

I tried to put the html error page at the DocumentRoot var/www, at var/www/error. Try to uncomment all the file /etc/apache2/conf.d/localized-error-pages that sets all errors to custom pages with internationalization that are at /usr/share/apache2/error. And as the messages inside this files are the same as the default, the line

Additionally, a 503 Service Temporarily Unavailable error was encountered while trying to use an ErrorDocument to handle the request. is not shown anymore. But if I change the line

`ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var`

at the localized-error-pages file to a new html placed at the same page, the error is back and the page is not shown. If I edit the file HTTP_SERVICE_UNAVAILABLE.html.var nothing change at the browser message too.

Some more information: I'm using apache2 just to redirect all request on port 80 to tomcat at port 8089 via an worker. My configuration files are https://dl.dropboxusercontent.com/u/1105054/apache.zip

Renita answered 21/10, 2014 at 14:38 Comment(0)
D
7

This took me way tooo long (partially due to spelling), but I thought I'd post my whole virtual host file since it might be useful.

You'll want to make sure you've specified a DocumentRoot, and that you do the ProxyPass /file.html ! before your main ProxyPass /.

<VirtualHost *:443>
    DocumentRoot /var/www/html
    #ProxyPreserveHost On

    <IfModule env_module>
         # Fake SSL if Loadbalancer does SSL-Offload 
         SetEnvIf Front-End-Https "^on$" HTTPS=on
    </IfModule>

    SSLEngine on
    SSLCertificateFile file
    SSLCertificateKeyFile file
    SSLCertificateChainFile file

    ProxyPass /maintenance-message.html !
    ProxyPass /maintance-message_files !
    ProxyPass / "ajp://localhost:8009/"
    ProxyPassReverse / "ajp://localhost:8009/"
    ServerName server.something.com:443
    ErrorDocument 503 /maintenance-message.html
</VirtualHost>
Distefano answered 31/3, 2016 at 18:58 Comment(3)
After hours of searching and finding nothing! Thanks! I was missing ProxyPass /maintenance-message.html !. Still dont know what the '!' does but who cares?! it works!Uhhuh
If I remember correctly, it will exclude the maintenance-message.html file from being proxied and will instead serve it from /var/www/html. (So the ! inverts the command to say don't ProxyPass this file or folder.)Distefano
Yes I figured it out eventually. Thanks!Uhhuh
A
4

In my case I just added this ProxyPass line to my virtualserver config:

ProxyPass /serverError.html !
ErrorDocument 503 /serverError.html

That tells the proxy to go to the DocumentRoot and search for the error page.

Also you may find useful this answer: https://stackoverflow.com/a/13019667

Acute answered 6/1, 2015 at 16:27 Comment(0)
G
1

I faced the same issue too and after deep searching I found here the best (and only?) solution from @Loren.

Worked after setting ProxyPass /file.html ! before the main ProxyPass / and NOT after. Also, DocumentRoot is needed as well.

Gains answered 27/8, 2019 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.