预先感谢您的任何帮助。
我尝试使用 Apache 作为使用 WSS 的 Web 浏览器和后端 WS 服务器进程之间的代理。
浏览器 Apache RabbitMQ Stomp
我在 Apache 中正确设置了 HTTPS,并通过 443 提供页面。
在 Apache 站点配置中: .../sites-enabled/site.conf
<VirtualHost *:80>
RewriteEngine on
RewriteCond %{SERVER_NAME} =MYSERVER.com [OR]
RewriteCond %{SERVER_NAME} =www.MYSERVER.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLProxyEngine On
SSLCertificateFile /etc/letsencrypt/live/MYSERVER.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/MYSERVER.com/privkey.pem
Redirect /wss /wss/
ProxyPass /wss/ ws://127.0.0.1:15674/stomp/websocket/
ProxyPassReverse /ws/ wss://127.0.0.1:15674/stomp/websocket/
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName MYSERVER.com
ServerAlias www.MYSERVER.com
</VirtualHost>
浏览器中的 JavaScript:
<script>
var ws = new WebSocket('wss://MYSERVER.com:443/wss');
var client = Stomp.over(ws);
在 Chrome 调试器中我看到:
与“wss://MYSERVER.com/wss”的 WebSocket 连接失败:WebSocket 握手期间出错:意外的响应代码:302
仅使用 ws 直接指向后端就可以很好地工作,但我需要让 wss 工作。
我尝试获得与此示例类似的解决方案,但无法:Apache:代理 websocket wss 到 ws https://stackoverflow.com/questions/31211828/apache-proxy-websocket-wss-to-ws