2015-06-30 3 views
5

Ich versuche websockets mit httpd proxy und reverse proxy zu konfigurieren, aber es scheint nicht zu funktionieren. Wenn ich direkt den Tomcat-Server verwende, ist alles in Ordnung, wenn ich es über Apache httpd anrufe, ist der Antwortstatus . Das bedeutet, Apache httpd kann die Websocket-Anfrage nicht interpretieren und das Protokoll umschalten, oder?Konfiguriere gesicherte websockets mit Apache httpd 2.4.6 und Tomcat 8

Das ist meine httpd Config für meine App:

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> 

Und dies ist der Connector-Konfiguration für Apache Tomcat:

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

Antwort

3

ich das Problem denke, Schrägstriche sein kann:

HINWEIS: Achten Sie unbedingt auf die Schrägstriche "/" oder deren Fehlen! WebSocket url Endpunkt

Proxypass/ws/WSS: // localhost: 8443/ws

Proxypassreverse/ws/WSS: // localhost: 8443/ws

Weitere Informationen hier: tunneling-secure-websocket-connections-with-apache

+0

Sorry, habe ich versucht, mit und ohne Schrägstriche ... immer noch nicht funktioniert ... Ich habe versucht, die Dokumentation zu folgen, aber es kommt nichts heraus .. Das Problem ist, weil ich manchmal Fehler 200 bekomme, dies bedeutet httpd tut die Umleitung aber nicht in einer richtigen Weise, oder? – spauny

+0

Können Sie mir die Anforderungs- und Antwortheader anzeigen? –

1

Dies funktionierte für mich, aber ich brauchte eine zusätzliche Zeile wegen Java Spring Framework auf meiner internen Anwendung.

Hier ist die gesamte Lösung als Proxy-Datei:

<Location /outside-app> 
    # WEBSOCKET 
    Header always add "Access-Control-Allow-Origin" "*" 
    ProxyPass wss://internal.company.com:11111/application 

    RewriteEngine on 
    Require all granted 
    RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC] 
    RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC] 
    RewriteRule .* https://internal.company.com:11111/application/$1 [P,L] 

    # REVERSE PROXY 
    ProxyPass https://internal.company.com:11111/application 
    ProxyPassReverse https://internal.company.com:11111/application 
</Location>