使用Apache httpd 2.4.6和Tomcat 8配置安全的websockets

spa*_*uny 5 java apache tomcat websocket atmosphere

我正在尝试使用httpd代理和反向代理配置websockets但它似乎不起作用.如果我直接使用tomcat服务器一切都很好,如果我通过apache httpd调用它,响应状态为200.这意味着apache httpd无法解释websocket请求并切换协议,对吧?

这是我的应用程序的httpd配置:

LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so

Listen 443 https


SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog

SSLSessionCache         shmcb:/run/httpd/sslcache(512000)
SSLSessionCacheTimeout  300

SSLRandomSeed startup file:/dev/urandom  256
SSLRandomSeed connect builtin

SSLCryptoDevice builtin


<VirtualHost 10.224.130.50:80>

    ServerName myhost
    Redirect permanent / https://myhost/

</VirtualHost>

<VirtualHost 10.224.130.50:443>

    ServerName myhost
    ErrorLog logs/myhost.error.log
    CustomLog logs/myhost.access.log common

    ProxyPass /ws/       wss://localhost:8443/ws/ retry=0
    ProxyPassReverse /ws/ wss://localhost:8443/ws/ retry=0

    ProxyPass / https://myhost:8443/ connectiontimeout=600 timeout=1200
    ProxyPassReverse / https://myhost:8443/


    SSLEngine on
    SSLProtocol all -SSLv2 -SSLv3
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
    SSLProxyEngine on
        SSLProxyVerify none 
        SSLProxyCheckPeerCN off
        SSLProxyCheckPeerName off
        SSLProxyCheckPeerExpire off
    SSLCertificateFile    "/etc/pki/tls/certs/myhost.cer"
    SSLCertificateKeyFile "/etc/pki/tls/private/myhost.key"

</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

这是Apache Tomcat的Connector配置:

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" 
           keystoreFile="/root/.keystore"
           keystorePass="password" />
Run Code Online (Sandbox Code Playgroud)

Jac*_*son 3

我认为问题可能出在斜杠上:

注意:请严格注意斜杠“/”或缺少斜杠!WebSocket url 端点

ProxyPass /ws/ wss://localhost:8443/ws

ProxyPassReverse /ws/ wss://localhost:8443/ws

更多信息请参见: tunneling-secure-websocket-connections-with-apache