How to made Websocket traffic to go via HAProxy

The solution was simple: Tell HAProxy to tag Websocket traffic, and set up a separate but otherwise identical backend for this specific use case.

One of typical applications which is using Websocket traffic is Slack. An excelent opensource  alternative of it named Mattermost. The result looks something like this in the config file named haproxy.conf:

acl host_ws hdr_beg(Host) -i ws.
acl hdr_connection_upgrade hdr(Connection) -i upgrade
acl hdr_upgrade_websocket hdr(Upgrade) -i websocket
use_backend bk_ws_mattermost if host_ws { hdr(Host) -i }
use_backend bk_ws_mattermost if hdr_connection_upgrade hdr_upgrade_websocket { hdr(Host) -i }
use_backend bk_mattermost if { hdr(Host) -i }

backend bk_mattermost
server mattermost check

backend bk_ws_mattermost
server mattermost check

Here is a good article how to install Mattermost server on FreeBSD inside a jail.

Share with Me via Nextcloud