Configurez des websockets sécurisés avec Apache httpd 2.4.6 et Tomcat 8

J’essaie de configurer les websockets à l’aide du proxy httpd et du proxy inverse, mais cela ne semble pas fonctionner. Si j’utilise directement le serveur tomcat, tout va bien, si je l’appelle via Apache httpd, le statut de la réponse est 200 . Cela signifie qu’apache httpd ne peut pas interpréter la requête websocket et changer le protocole, non?

Ceci est ma configuration httpd pour mon application:

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  ServerName myhost Redirect permanent / https://myhost/   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"  

Et voici la configuration du connecteur pour Apache Tomcat:

  

Je pense que le problème peut être des barres obliques:

REMARQUE: Faites très attention aux barres obliques “/” ou à leur absence! Point de terminaison de l’URL WebSocket

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

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

Plus d’informations ici: tunneling-secure-websocket-connections-with-apache

Cela a fonctionné pour moi, mais j’avais besoin d’une ligne supplémentaire à cause du framework Java Spring sur mon application interne.

Voici la solution complète en tant que fichier proxy:

  # 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