At Flexiant, we had a need for a general websocket to tcp proxy. A cute apache module to do extensible web-sockets programming has been developed by self.disconnect, and is available on github here. I’ve hacked around with this to produce a generic, apache licensed, websocket proxy. A websocket connection is made over HTTP or HTTPS to apache, this calls the websocket module, which in turn calls my module, which makes an outbound tcp connection.

Some features:

• It supports base64 and text format sockets. So it will thus process (for instance) VNC which works using base64 encoding.
• Configuration is supplied through normal apache directory based configuration (see details below).
• It’s extensible (currently by changing the code, rather than calling additional modules)

The configuration section looks like this, in this case set up to proxy VNC using a novnc client:

<IfModule mod_websocket.c>
<Location /vncproxy>
SetHandler websocket-handler
WebSocketHandler  /usr/lib/apache2/modules/mod_websocket_tcp_proxy.so tcp_proxy_init
WebSocketTcpProxyBase64 on
WebSocketTcpProxyHost 192.168.199.199
WebSocketTcpProxyPort 5900
WebSocketTcpProxyProtocol base64
</Location>
</IfModule>


Note that the parameter you specify for Location must not be a file or directory that exists with your docroot, or you will just get 404 or similar. So, in the above example you must not have a file or directory at \${DOCROOT}/vncproxy.

I discovered that on a default apache install, you may also want to change the RequestReadTimeout, i.e.

<IfModule reqtimeout_module>

sudo apxs2 -c -i -a -I.. mod_websocket_tcp_proxy.c