title: Hosting multiple Node.JS applications recognizing subdomains with a proxy server
body: <p>I am trying to redirect certain subdomains to a specific port on my ubuntu AWS EC2 virtual server. Already tried it with DNS and that wouldn't work so based on the following topics, <a href="https://stackoverflow.com/questions/10930564/default-route-using-node-http-proxy">Default route using node-http-proxy?</a> and <a href="https://stackoverflow.com/questions/10985350/how-do-i-use-node-js-http-proxy-for-logging-htttp-traffic-in-a-computer">How do I use node.js http-proxy for logging HTTP traffic in a computer?</a>, I was trying to create a Node.JS proxy server with logging. That said I mixed it a bit up together (I'm new to Node.JS, still learning) and made the following script:</p>
  
  <pre><code>var httpProxy = require('http-proxy');
  
  var PORT = 80;
  
  logger = function() {
     return function (request, response, next) {
      // This will run on each request.
      console.log(JSON.stringify(request.headers, true, 2));
      next();
    }
  }
  
  var options = {
    // this list is processed from top to bottom, so '.*' will go to
    // 'http://localhost:3000' if the Host header hasn't previously matched
    router : {
      'dev.domain.com': 'http://localhost:8080',
      'beta.domain.com': 'http://localhost:8080',
      'status.domain.com': 'http://localhost:9000',
      'health.domain.com': 'http://localhost:9000',
      'log.domain.com': 'http://localhost:9615',
      '^.*\.domain\.com': 'http://localhost:8080',
      '.*': 'http://localhost:3000'
    }
  };
  
  // Listen to port 80
  httpProxy.createServer(logger(), options).listen(PORT);
  console.log("Proxy server started, listening to port" + PORT);
  </code></pre>
  
  <p>Well what happens is that I keep getting the following error and can't figure out how to put this to work:</p>
  
  <pre><code>$node proxyServer.js
  Proxy server started, listening to port80
  
  events.js:72
          throw er; // Unhandled 'error' event
                ^
  Error: listen EACCES
      at errnoException (net.js:904:11)
      at Server._listen2 (net.js:1023:19)
      at listen (net.js:1064:10)
      at Server.listen (net.js:1138:5)
      at ProxyServer.listen (/home/ubuntu/QuantBull-Project/node_modules/http-proxy/lib/http-proxy/index.js:130:16)
      at Object.&lt;anonymous&gt; (/home/ubuntu/QuantBull-Project/proxyServer.js:28:43)
      at Module._compile (module.js:456:26)
      at Object.Module._extensions..js (module.js:474:10)
      at Module.load (module.js:356:32)
      at Function.Module._load (module.js:312:12)
  </code></pre>
  
  <p>In short I'm trying to receive http request on port 80 and if it came from sub1.domain.com it will be redirected to portA and if it came frome sub2.domain.com it'll be redirected to portB from the same IP adress and both ports are open to the public.</p>
  
  <p>Can someone explain how to fix this and explain why it happens?</p>