代理背后的Web套接字

时间:2017-05-16 11:28:53

标签: websocket proxy apache2 spring-websocket

我有Spring Boot应用程序,在Apache 2后面运行WebSocket。尝试连接时,我收到以下错误:

  • 服务器日志:

    Handshake failed due to invalid Upgrade header: null
    
  • 客户日志:enter image description here

这是Apache 2配置:

<IfModule mod_ssl.c>
<VirtualHost *:443>

ServerAdmin tom_marik@hotmail.com
ServerName www.languageexchange.eu

ProxyPass "/ws2/"  "ws://www.languageexchange.eu:92/"
ProxyPass "/wss2/" "wss://www.languageexchange.eu:92/"

ProxyPass           /   http://31.31.74.54:92/
ProxyPassReverse    /   http://31.31.74.54:92/
ProxyPassReverseCookiePath  /    /
ErrorLog /var/log/apache2/languageexchange.log
LogLevel warn

RewriteEngine on
[END,QSA,R=permanent]
SSLCertificateFile /etc/letsencrypt/live/languageexchange.eu/cert.pem
SSLCertificateKeyFile 
/etc/letsencrypt/live/languageexchange.eu/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile 
/etc/letsencrypt/live/languageexchange.eu/chain.pem

</VirtualHost>
</IfModule>

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

您需要安装 mod_proxy_wstunnel mod_proxy mod_ssl )。然后在Apache的配置中:

ProxyPass /ws2  ws://languageexchange.eu:92 keepalive=On
ProxyPassReverse /ws2  ws://languageexchange.eu:92
ProxyPass /wss2 wss://languageexchange.eu:92 keepalive=On
ProxyPassReverse /wss2  wss://languageexchange.eu:92

如果这是一台机器,最好设置 127.0.0.1 而不是 languageexchange.eu ,所以:

ProxyPass /ws2  ws://127.0.0.1:92 keepalive=On
ProxyPassReverse /ws2  ws://127.0.0.1:92
ProxyPass /wss2 wss://127.0.0.1:92 keepalive=On
ProxyPassReverse /wss2  wss://127.0.0.1:92