daily system administration

Linux, Debian and the rest
any questions or comments: Tom@d7031.de

Apache 2 customized error pages and exceptions for websockets

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