title: How to run node.js app on port 80 using http-proxy?
body: <p>I want to run my node.js app on port 80 on Apache server. I have tried 2 methods one via Apache:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName domainName.com
      ServerAlias www.domainName.com
  
      ProxyRequests off
  
      &lt;Proxy *&gt;
          Order deny,allow
          Allow from all
      &lt;/Proxy&gt;
  
      &lt;Location /&gt;
          ProxyPass http://domainName:8080
          ProxyPassReverse http://domainName:8080
      &lt;/Location&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>When I use this I get <code>502 proxy error</code> in Chrome console. The server cannot find my <code>CSS</code> and <code>Socket.io</code> and other <code>JS</code> files. </p>
  
  <p><strong>UPDATE: I solved this error for CSS and normal .js files by putting <code>http://domainName.com:8080/</code> in front of the links. But the problem still exist for socket.io! Socket.io cannot be found!</strong></p>
  
  <p>And the second method is using <code>http-proxy</code> module (this is the example I  found, please see the comment below this post):</p>
  
  <pre><code>var http = require('http'),
  httpProxy = require('http-proxy'),
  proxyServer = httpProxy.createServer ({
      hostnameOnly: true,
      router: {
          'domain.com':       '127.0.0.1:81',
          'domain.co.uk':     '127.0.0.1:82',
          '127.0.0.1':        '127.0.0.1:83'
      }
  });
  
  proxyServer.listen(80);
  </code></pre>
  
  <p>Which was explained here: <a href="https://stackoverflow.com/questions/11172351/how-to-put-nodejs-and-apache-in-the-same-port-80">how to put nodejs and apache in the same port 80</a></p>
  
  <p>I don't know how to get this one working for my code, since I'm using <code>Express</code>.</p>
  
  <p>This is my relevant part of code:</p>
  
  <pre><code>var express = require('express');
  var http = require('http');
  var io = require('socket.io');
  var connect = require('connect');
  var sanitize = require('validator').sanitize;
  var app = express();
  var MemoryStore = express.session.MemoryStore;
  var server = http.createServer(app);
  
  var sessionStore = new MemoryStore();
  var io = io.listen(server);
  app.configure(function() {
      //app.use(express.logger());
      app.use(express.cookieParser());
      app.use(express.bodyParser());
      app.use(express.methodOverride());
      app.use(express.session({ 
              store: sessionStore, 
              secret: 'someSecret',
              key: 'cookie.sid', maxAge: null }));
              });
  app.use(app.router);
  app.use("/styles", express.static(__dirname + '/styles'));
  app.use("/images", express.static(__dirname + '/styles/images'));
  app.use("/js", express.static(__dirname + '/js'));
  // routing
  app.get('/', function (req, res) {
    res.sendfile(__dirname + '/index.html');
  });
  
  server.listen(8080);
  </code></pre>
  
  <p><strong>I prefer the second method, so if someone could help me get it to work I'd really appreciate it.</strong> </p>