Apache HTTP Server Version 2.4
Description: | Websockets support module for
mod_proxy |
---|---|
Status: | Extension |
Module Identifier: | proxy_wstunnel_module |
Source File: | mod_proxy_wstunnel.c |
Compatibility: | Available in httpd 2.4.5 and later |
This module requires the service of mod_proxy
. It provides support for the tunnelling of web
socket connections to a backend websockets server. The connection
is automatically upgraded to a websocket connection:
Upgrade: WebSocket Connection: Upgrade
Proxying requests to a websockets server like echo.websocket.org
can be done using the
ProxyPass
directive:
ProxyPass "/ws2/" "ws://echo.websocket.org/" ProxyPass "/wss2/" "wss://echo.websocket.org/"
Proxying both HTTP and websockets at the same time, with a specific set of URL's being
websocket-only, can be done by specifying the websockets
ProxyPass
directive before the
HTTP directive:
ProxyPassMatch ^/(myApp/ws)$ ws://example.com:9080/$1 ProxyPass / http://example.com:9080/
Proxying both HTTP and websockets at the same time, where the websockets URL's are not
websocket-only or not known in advance can be done by using the
RewriteRule
directive to
configure the websockets proxying:
ProxyPass / http://example.com:9080/ RewriteEngine on RewriteCond %{HTTP:Upgrade} websocket [NC] RewriteCond %{HTTP:Connection} upgrade [NC] RewriteRule ^/?(.*) "ws://example.com:9080/$1" [P,L]
Load balancing for multiple backends can be achieved using mod_proxy_balancer
.
In fact the module can be used to upgrade to other protocols, you can set the upgrade
parameter in the ProxyPass
directive to allow the module to accept other protocol.
NONE means you bypass the check for the header but still upgrade to WebSocket.
ANY means that Upgrade
will read in the request headers and use
in the response Upgrade