Apache 2 customized error pages and exceptions for websockets

By | 2016-03-16

Reverse Proxy with local error pages

At first create a local directory for serving your customized error pages

# local error pages
DocumentRoot /srv/busypage/
Alias /error/ /srv/busypage/
<Directory /srv/busypage/
           Options None
           AllowOverride None
           Require all granted
</Directory>

Now put your pages inside and configure your error pages:

ProxyErrorOverride      On
ErrorDocument   403     /error/error-403.html
ErrorDocument   404     /error/error-404.html
ErrorDocument   500     /error/error-500.html
ErrorDocument   503     /error/error-503.html

So far so easy.

Error pages and websockets

If you have a websocket in your backend, so this communication should be go through end to end to get the real backend error message. It takes me some time to find a solution for that. But it’s pretty easy. Just make an IF and NOT (!) statement with regex.

<If "! %{REQUEST_URI} =~ /websocket/">
    ProxyErrorOverride      On
    ErrorDocument   403     /error/error-403.html
    ErrorDocument   404     /error/error-404.html
    ErrorDocument   500     /error/error-500.html
    ErrorDocument   503     /error/error-503.html
</If>

Now the humans and the machines have there own error messages.

Tom

Leave a Reply

Your email address will not be published. Required fields are marked *

3 + 7 =