<-
Apache > HTTP Server > Documentation > Modules

Apache Module mod_proxy_wstunnel 6p491i

Available Languages:  fr 

Description: Websockets 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

Summary 6m2os

This module requires the service of mod_proxy. It provides for the tunnelling of web socket connections to a backend websockets server. The connection is automatically upgraded to a websocket connection:

HTTP Response 7e2j

Upgrade: WebSocket
Connection: Upgrade

Proxying requests to a websockets server like echo.websocket.org can be done using the Proxy directive:

Proxy "/ws2/"  "ws://echo.websocket.org/"
Proxy "/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 Proxy directive before the HTTP directive:

ProxyMatch ^/(myApp/ws)$  ws://backend.example.com:9080/$1
Proxy / http://backend.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:

Proxy / 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 other protocols, you can set the upgrade parameter in the Proxy directive to allow the module to accept other protocol. NONE means you by the check for the header but still WebSocket. ANY means that Upgrade will read in the request headers and use in the response Upgrade

 Apache!

Directives 1a4l6m

Bugfix checklist 4i2533

See also 27136x

top

ProxyWebsocketFallbackToProxyHttp Directive 5i521f

Description: Instructs this module to let mod_proxy_http handle the request
Syntax: ProxyWebsocketFallbackToProxyHttp On|Off
Default: ProxyWebsocketFallbackToProxyHttp On
Context: server config, virtual host
Status: Extension
Module: mod_proxy_wstunnel
Compatibility: Available in httpd 2.4.48 and later

Since httpd 2.4.47, mod_proxy_http to this, which is the case by default.

Setting to Off lets mod_proxy_wstunnel handle WebSocket requests as in httpd 2.4.46 and earlier.

Available Languages:  fr 

top

Comments 2p1l6j

Notice:
This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed by our s if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Libera.chat, or sent to our mailing lists.