大网数据广告活动
服务器运维问答

Apache mod_proxy: forward secure websocket to non-secure

· 52CE 我爱测

The websocket library I rely on ( PHP-Websockets ) does not yet support secure sockets ( wss ). My website is served over https though, so I cannot use insecure ws connections. I'm trying to use Apache's mod_proxy to forward the …

问题原文

原帖链接 · BeetleJuice · CC BY-SA 3.0

The websocket library I rely on (PHP-Websockets) does not yet support secure sockets (wss). My website is served over https though, so I cannot use insecure ws connections.

I'm trying to use Apache's mod_proxy to forward the secure request that comes from the browser on to the client.

Javascript

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

Apache VirtualHosts

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

Upon trying to connect, the browser receives a 500 Server Error. The logs show:

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.

I've confirmed that if I remove the proxy rules, stop redirecting users to https and try to connect to insecure sockets from the browser: new Websocket('ws://example.com/'), things work just fine.

My loaded Apache modules include mod_ssl.c, mod_proxy.c and mod_proxy_http.c

Apache 2.4

已采纳解答

原帖链接 · BeetleJuice · CC BY-SA 3.0

To get things to work, I also needed to load mod_proxy_wstunnel

Once I did, this ruleset got things working: (in the VirtualHost of the domain that receives and proxies the websocket request)

<IfModule mod_proxy.c>
    ProxyPass "/_ws_/" "ws://127.0.0.1:8080/"
    ProxyPassReverse "/_ws_/" "ws://127.0.0.1:8080/"
</IfModule>

The browser can then contact the backend WS server through the HTTPS port:

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。