【发布时间】:2016-10-20 10:38:46
【问题描述】:
我使用Undertow 服务器启用了 WebSocket。当我直接运行 Undertow 服务器时,WebSockets 运行良好。我使用 HTTPS 提供我的页面,并在 javascript 中使用“wss:”测试端点:它可以工作。
但是现在,我尝试使用 Apache 作为反向代理,我希望它让 WebSocket 连接到达 Undertow 服务器。这是我当前的虚拟主机:
<VirtualHost *:80 *:443>
ServerName test.example.org
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.org/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.org/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.org/chain.pem
ProxyPass / http://test.example.org:44444/
ProxyPassReverse / http://test.example.org:44444/
</VirtualHost>
在这里,Undertow 作为 HTTP 服务器(不是 HTTPS)在端口 44444 上启动,SSL 安全性由 Apache 完成。
所有 HTML 页面都运行良好,但是当我尝试启动 WebSocket 连接时,我收到此错误(Chrome):
WebSocket connection to 'wss://test.example.org/websockets/echo' failed: Error during WebSocket handshake: 'Upgrade' header is missing
而且,当我查看“网络”选项卡时,我发现服务器的响应中确实缺少两个标头,当进行“wss://”调用时:“Connection: Upgrade”和“Upgrade: WebSocket” ”。当我不使用 Apache 直接连接到 Undertow 时,这些标头存在。
“Sec-WebSocket-Accept”和“Sec-WebSocket-Location”标头在那里,但我想这是第二个问题,“Sec-WebSocket-Location”是“ws://test.example.org/websockets/echo”不是 'wss://test.example.org/websockets/echo' 因为 Undertow 在 HTTP 上运行,而不是 HTTPS。
最后,mod_proxy_wstunnel 文档说“连接会自动升级到 websocket 连接”。这是什么意思? Apache 自己将 HTTP 连接升级为 WebSocket 连接?这不是我想要的!我想自己使用 Undertow 处理初始 HTTP 请求和升级过程。我使用来自初始 HTTP 连接的信息来验证用户是否可以连接到请求的端点,如果可以,我以编程方式调用 Undertow 的 WebSocketProtocolHandshakeHandler#handleRequest(exchange) 以升级到 WebSocket 连接。我只是希望 Apache 让一切顺利通过而不会干扰。
有关如何在 Apache 反向代理后面使用 Undertow 运行 WebSockets 的任何帮助?
【问题讨论】:
标签: apache websocket reverse-proxy undertow