title: Using same port for IIS and Node JS
body: <p>I have a web app built with PHP on IIS as backend and Node.JS socket.io for realtime communication, however I need to run both app (IIS and Node.JS) on a same port (443) to secure both connection, so im creating reverse proxy like this :</p>
  
  <pre><code>var httpProxy = require('http-proxy');
  proxy = httpProxy.createProxyServer({}),
  url = require('url');
  http = require('http');
  
  http.createServer(function(req, res) {
      var hostname = req.headers.host.split(":")[0];
      var pathname = url.parse(req.url).pathname;
      if(pathname == '/realtime_script')
              proxy.web(req, res, { target: 'http://localhost:8000/socket.io/socket.io.js' });
      else if(pathname.indexOf("/socket.io") &gt; -1)
              proxy.web(req, res, { target: 'http://localhost:8000'+req.url });
      else
              proxy.web(req, res, { target: 'http://localhost:8080' });
  
  }).listen(80, function() {
      console.log('proxy listening on port 9000');
  });
  </code></pre>
  
  <p>I set socket.io to listen to port 8000 and IIS bind to port 8080, I managed to access home page using <a href="http://localhost" rel="nofollow">http://localhost</a>, everything loads and connected perfectly (including socket.io), however every time a redirect happened (e.g submitting form or clicking a link), the node js crashed with this message :</p>
  
  <pre><code>C:\inetpub\wwwroot\node\node_modules\http-proxy\lib\http-proxy\index.js:119
  throw err;
        ^Error: socket hang up
  at createHangUpError (http.js:1472:15)
  at Socket.socketCloseListener (http.js:1522:23)
  at Socket.emit (events.js:95:17)
  at TCP.close (net.js:465:12)
  </code></pre>
  
  <p>anybody can tell me what's wrong here?</p>
  
  <p>Thank you</p>