Apache mod_proxy:将安全的 websocket 转发到非安全的

Apache mod_proxy: forward secure websocket to non-secure

我依赖的 websocket 库 (PHP-Websockets) 尚不支持安全套接字 (wss)。我的网站是通过 https 服务的,所以我不能使用不安全的 ws 连接。

我正在尝试使用 Apache's mod_proxy 将来自浏览器的安全请求转发到客户端。

Javascript

var ws = new WebSocket('wss://example.com/_ws_/');

Apache 虚拟主机

ProxyPass        "/_ws_/" "ws://127.0.0.1:8080/"
ProxyPassReverse "/_ws_/" "ws://127.0.0.1:8080/"
# I've also tried "/_ws_/" "ws://example.com:8080/"  Same error below

尝试连接时,浏览器收到 500 Server Error。日志显示:

No protocol handler was valid for the URL /_ws_/. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

我已经确认,如果我删除代理规则,停止将用户重定向到 https 并尝试从浏览器连接到不安全的套接字:new WebSocket('ws://example.com/'),一切正常。

我加载的 Apache 模块包括 mod_ssl.cmod_proxy.cmod_proxy_http.c

Apache 2.4

要反向代理 WebSockets,您还需要加载 mod_proxy_wstunnel 模块。