title: Trying to set up Secure WebSocket on Apache 2.4.29 and Ubuntu 18.04
body: <p>I have been trying for weeks to get a websocket working on my SSL secure Apache 2.4.29 server running on Ubuntu 18.04.</p>
  <p>Here is the code I am using to set up a secure wss:// protocol websocket:</p>
  <pre><code><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>  
  
  // Minimal amount of secure websocket server
  var fs = require('fs');
  
  // read ssl certificate
  var privateKey = fs.readFileSync('/path/to/privkey.pem', 'utf8');
  var certificate = fs.readFileSync('/path/to/fullchain.pem', 'utf8');
  
  var credentials = {
      key: privateKey,
      cert: certificate
  };
  var https = require('https');
  
  //pass in your credentials to create an https server
  var httpsServer = https.createServer(credentials);
  httpsServer.listen(8080);
  
  var WebSocketServer = require('ws').Server;
  var wss = new WebSocketServer({
      server: httpsServer
  });
  
  httpsServer.on('upgrade', wss.handleUpgrade);
  
  wss.on('connection', function connection(ws) {
      wss.on('message', function incoming(message) {
          console.log('received: %s', message);
          wss.send('reply from server : ' + message)
      });
  
      wss.send('something');
  });</code></pre>
  </div>
  </div>
  
  </code></pre>
  <p>Here is some of my ssl &lt;VirtualHost *:443&gt; where I am trying to do a ProxyPass:</p>
  <pre><code>&gt;     LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so
  &gt;     LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
  &gt;     LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so
  &gt;     LoadModule proxy_connect_module /usr/lib/apache2/modules/mod_proxy_connect.so
  &gt;     LoadModule proxy_express_module /usr/lib/apache2/modules/mod_proxy_express.so
  &gt;     LoadModule proxy_fcgi_module /usr/lib/apache2/modules/mod_proxy_fcgi.so
  &gt;     LoadModule proxy_ftp_module /usr/lib/apache2/modules/mod_proxy_ftp.so
  &gt;     LoadModule proxy_html_module /usr/lib/apache2/modules/mod_proxy_html.so
  &gt;     LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
  &gt;     LoadModule proxy_scgi_module /usr/lib/apache2/modules/mod_proxy_scgi.so
  &gt;     LoadModule proxy_wstunnel_module /usr/lib/apache2/modules/mod_proxy_wstunnel.so
  &gt;     LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
  &gt; 
  &gt;     LoadModule log_forensic_module /usr/lib/apache2/modules/mod_log_forensic.so
  &gt;     &lt;IfModule log_forensic_module&gt;
  &gt;     ForensicLog /var/log/apache2/forensic_log
  &gt;     &lt;/IfModule&gt;
  &gt; 
  &gt;      SSLEngine on
  &gt;         SSLCertificateFile    /etc/letsencrypt/live/taskhandle.io/fullchain.pem
  &gt;         SSLCertificateKeyFile /etc/letsencrypt/live/taskhandle.io/privkey.pem
  &gt; 
  &gt;     AllowEncodedSlashes NoDecode
  &gt; 
  &gt;         #SSL Connect
  &gt;         SSLProxyVerify none
  &gt;         SSLProxyCheckPeerCN off
  &gt;         SSLProxyCheckPeerName off
  &gt;         SSLProxyCheckPeerExpire off
  &gt; 
  &gt;      SSLProxyEngine on
  &gt;      RewriteEngine on
  &gt;     ProxyRequests off
  &gt;     ProxyPreserveHost On
  &gt;      RewriteCond %{HTTP:Upgrade} websocket [NC]
  &gt;      RewriteCond %{HTTP:Connection} upgrade [NC]
  &gt;      RewriteRule /(.*) &quot;wss:/localhost:8080/$1&quot; [P,L]
  &gt; 
  &gt;     # the WebSocket Proxying
  &gt;     ProxyPass &quot;/app/ws&quot; &quot;ws://localhost:8090/app/ws&quot;
  &gt;     # the common app proxying
  &gt;     ProxyPass &quot;/app&quot; &quot;http://localhost:8090/app&quot;
  &gt;     ProxyPassReverse &quot;/app&quot; &quot;http://localhost:8088/app&quot;
  &gt; 
  &gt;     ProxyPass &quot;/wss2&quot; &quot;wss://localhost:8080/&quot;
  &gt;     ProxyPassReverse &quot;/wss2&quot; &quot;wss://localhost:8080/&quot;
  &gt; 
  &gt;     ProxyPass &quot;/wss&quot; &quot;ws://localhost:8080/&quot;
  &gt;     ProxyPassReverse &quot;/wss&quot; &quot;ws://localhost:8080/&quot;
  &gt; 
  &gt;     ServerName taskhandle.io
  &gt;     SSLCertificateFile /etc/letsencrypt/live/taskhandle.io/fullchain.pem
  &gt;     SSLCertificateKeyFile /etc/letsencrypt/live/taskhandle.io/privkey.pem
  &gt;     Include /etc/letsencrypt/options-ssl-apache.conf
  &gt;     &lt;/VirtualHost&gt;
  &gt;     &lt;/IfModule&gt;
  </code></pre>
  <p>But when I run the websocket using 'nodejs index.js' from the command line, then try to access the websocket from a client browser using</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>    var conn = new WebSocket('wss://mywebsite.io:8080');
          conn.onopen = function(e) {
              console.log("Connection established!");
          };</code></pre>
  </div>
  </div>
  </p>
  <p>I get a 500 response code on the client side, and in the apache error log it says:</p>
  <pre><code>&gt; &quot;[Sun Jun 21 21:10:20.487029 2020] [proxy:warn] [pid 30076] [client
  &gt; 208.87.239.180:34995] AH01144: No protocol handler was valid for the URL /wss2 (scheme 'wss'). If you are using a DSO version of mod_proxy,
  &gt; make sure the proxy submodules are included in the configuration using
  &gt; LoadModule.&quot;
  </code></pre>
  <p>which is strange because I am pretty sure I have all the submodules enabled and loaded. I wonder if it might be an issue with the headers not being proxied. Here are the headers being received in my access log when I try to establish the websocket connection:</p>
  <blockquote>
  <pre><code>**GET /wss2 HTTP/1.1|Host:taskhandle.io|Pragma:no-cache|Cache-Control:no-cache|User-Agent:Mozilla/5.0
  </code></pre>
  <p>(Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
  Chrome/81.0.4044.138
  Safari/537.36|Origin:https%3a//stackoverflow.com|Sec-WebSocket-Version:13|Accept-Encoding:gzip,
  deflate|Accept-Language:en-US,en;q=0.9|Cookie:_ga=GA1.2.1978077118.1589209571;
  _gid=GA1.2.1472919475.1592682267|Sec-WebSocket-Key:WyjiHAZ3HPj0lcvvVGzq9Q==|Sec-WebSocket-Extensions:permessage-deflate;
  client_max_window_bits|Via:1.1 hosted.websense
  02o|X-Forwarded-For:68.12.180.212|Client-IP:68.12.180.212
  -30076:5eefccbc:1**</p>
  </blockquote>
  <p>If you notice there is not a Connection: Upgrade or Upgrade: websocket header present in the request header being received in my access log...</p>
  <p>Please help I have been struggling for weeks to get this websocket working. I have also tried setting up the websocket using Ratchet in PHP but still having the same issue whether I use node or ratchet.</p>