title: WebSocket Error in connection establishment: net::ERR_CONNECTION_CLOSED
body: <p>I am getting this error when I attempt to establish a <code>wss</code> connection with my server:</p>
  
  <blockquote>
    <p>WebSocket connection to 'wss://mydomain:3000/' failed: Error in
    connection establishment: net::ERR_CONNECTION_CLOSED</p>
  </blockquote>
  
  <p>I currently have a apache2 virtual host configuration setup to listen for requests on port 443 and 80:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
          ServerName otherdomainname.co.uk
          ServerAlias www.otherdomainname.co.uk
  
          RewriteEngine On
          RewriteRule ^/(.*)$ /app/$1 [l,PT]
  
          JkMount /* worker2
  
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost _default_:443&gt;
          ServerName otherdomainname.co.uk
          ServerAlias www.otherdomainname.co.uk
  
          RewriteEngine On
          RewriteRule ^/(.*)$ /app/$1 [l,PT]
  
          SSLEngine On
          SSLCertificateFile /etc/apache2/ssl/apache.crt
          SSLCertificateKeyFile /etc/apache2/ssl/apache.key
  
          &lt;Location /&gt;
          SSLRequireSSL On
          SSLVerifyClient optional
          SSLVerifyDepth 1
          SSLOptions +StdEnvVars +StrictRequire
          &lt;/Location&gt;
  
          JkMount /* worker2
  
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>As you can see it uses the JkMount to pass the request to Tomcat which serves the webpage correctly on both HTTP and HTTPS.</p>
  
  <p>When I visit the site using the HTTP protocol on port 80 a WebSocket connection can be made using the <code>ws</code> protocol.</p>
  
  <p>When I visit the site using the HTTPS protocol on port 443 the site is served correctly but no WebSocket connection is made using <code>wss</code>.</p>
  
  <p>I am using the "ws" node.js module to provide the WebSocket server:</p>
  
  <pre><code>var WebSocketServer = require('ws').Server
    , wss = new WebSocketServer({ port: 3000 }),
    fs = require('fs');
  
  wss.on('connection', function connection(ws) {
    ws.on('message', function incoming(message) {
      console.log('received: %s', message);
  
      ws.send(message);
    ws.send('something');
  });
  </code></pre>
  
  <p>Why am I not able to successful connect to the WebSocket server using the <code>wss</code> protocol over <code>https</code>?</p>