5

I'm trying to configure websockets using httpd proxy and reverse proxy but it doesn't seem to work. If I use directly the tomcat server everything is fine, if I call it through apache httpd, the response status is 200. This means apache httpd cannot interpret the websocket request and switch the protocol, right?

This is my httpd config for my 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>

And this is the Connector config for 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" />
spauny
  • 4,976
  • 9
  • 44
  • 61

2 Answers2

3

I think the problem may be slashes:

NOTE: Pay strict attention to the slashes "/" or lack thereof! WebSocket url endpoint

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

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

More information here: tunneling-secure-websocket-connections-with-apache

dKen
  • 3,078
  • 1
  • 28
  • 37
Jacob Margason
  • 612
  • 4
  • 13
  • Sorry, I tried with and without slashes... still doesn't work... I tried to follow the docs but nothing comes out... the problem is because sometimes I get error 200, this means httpd does the redirect but not in a proper way, right? – spauny Jul 10 '15 at 11:56
  • Can you show me both the Request and Response headers? – Jacob Margason Jul 10 '15 at 12:09
1

This worked for me, but I needed one additional line because of Java Spring framework on my internal application.

Here's the whole solution as a proxy file:

<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>
Mark SMith
  • 11
  • 1