title: How to put haproxy in front of socket.io with SSL? Getting Mixed content warning
body: <p>I have been using this <a href="https://gist.github.com/christiannelson/3900758" rel="nofollow">setting</a> to put haproxy in front of node.js and socket.io. </p>
  
  <p>Some of the code in haproxy setting:</p>
  
  <pre><code>frontend wwws
      bind 0.0.0.0:443 ssl crt /etc/haproxy/ovee.pem
      timeout client 1h
      default_backend www_backend
  
      acl is_websocket hdr(Upgrade) -i WebSocket
      use_backend websocket_backend if is_websocket
  
      tcp-request inspect-delay 500ms
      tcp-request content accept if HTTP
      use_backend flashsocket_backend if !HTTP
  
  frontend flash_policy
      bind 0.0.0.0:843
      timeout client 5s
      default_backend nodejs_flashpolicy
  
  backend www_backend
      balance roundrobin
      option forwardfor
      server apache2 apache-backend:3001 weight 1 maxconn 1024 check  
      timeout connect 5s
      timeout http-request 3s
      timeout server 25s
  
  backend websocket_backend
      mode http
      option forwardfor
      option http-server-close
      option forceclose
      no option httpclose
      server server1 socket-backend:3000 weight 1 maxconn 16384 check
  </code></pre>
  
  <p>nodeServer.js</p>
  
  <pre><code>var fs =    require('fs');
  var express = require('express'), 
  app = express(), 
  http = require('http').createServer(app), 
  io = require("socket.io").listen(http), 
  </code></pre>
  
  <p>It seems to work well on first connection, but then the browser are blocking all the socket connection attempts for <code>Mixed Content</code>. </p>
  
  <pre><code>The page at 'https://domain.com/391' was loaded over HTTPS, 
   but requested an insecure XMLHttpRequest endpoint 
  'http://domain.com:3000/socket.io/?EIO=3&amp;transport=polling&amp;t=1456666556035-0'. 
   This request has been blocked; the content must be served over HTTPS.
  </code></pre>
  
  <p>I know it's due to my connection to socket.io is via <code>Http</code> instead of <code>Https</code></p>
  
  <p>client.js</p>
  
  <pre><code>socket = io.connect('http://domain.com:3000', {
    'force new connection': false,
    'reconnection delay': 500,
    'max reconnection attempts': 10
  }),
  </code></pre>
  
  <p>I have tried using SSL for nodeServer.js, but that doesn't connect to the socket, and I don't think it is necessary since I'm using haproxy to do all the forwarding:</p>
  
  <p>In nodeServer.js, I have changed to:</p>
  
  <pre><code>var fs =    require('fs'),
  sslOption = {
      key:    fs.readFileSync('/ssl/crt/zz.key'),
      cert:   fs.readFileSync('/ssl/crt/zz.crt'),
      ca:     fs.readFileSync('/ssl/crt/zz-ca.crt'),
      requestCert: true
  },
  express = require('express'), 
  app = express(), 
  https = require('https').createServer(app), 
  io = require("socket.io").listen(https), 
  </code></pre>
  
  <p>client.js</p>
  
  <pre><code>socket = io.connect('https://domain.com:3000', {
    'force new connection': false,
    'reconnection delay': 500,
    'max reconnection attempts': 10
  }),
  </code></pre>
  
  <p>Has anyone put haproxy in front of node.js and socket.io? What should I use to connect to socket.io from the client.js?</p>